Bug 77775 - [7 Regression] since r238559 Kdevelop gets miscompiled
Summary: [7 Regression] since r238559 Kdevelop gets miscompiled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P1 normal
Target Milestone: 7.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-09-28 12:34 UTC by Markus Trippelsdorf
Modified: 2016-10-04 21:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-09-29 00:00:00


Attachments
unreduced testcase (204.74 KB, application/x-xz)
2016-09-28 12:34 UTC, Markus Trippelsdorf
Details
good assembly (8.52 KB, text/plain)
2016-09-28 12:35 UTC, Markus Trippelsdorf
Details
bad assembly (8.39 KB, text/plain)
2016-09-28 12:35 UTC, Markus Trippelsdorf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2016-09-28 12:34:52 UTC
Created attachment 39717 [details]
unreduced testcase

Starting with r238559:

commit 5157eff877f9491e7c0fc9231ac2b686983eaa41
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jul 21 06:05:33 2016 +0000

            PR c++/71121 - -Waddress, constexpr, and PMFs.

            * cp-gimplify.c (cp_fully_fold): First call maybe_constant_value.

Kdevelop gets miscompiled and crashes on startup.

I've narrowed the issue to a single file.
See the attachments.

x4 sublime # diff -u good_ bad_
--- good_       2016-09-28 12:37:52.508094930 +0200
+++ bad_        2016-09-28 14:24:11.674668521 +0200
@@ -1016,7 +1016,7 @@
        pushq   %r13
        pushq   %r12
        pushq   %rbx
-       subq    $376, %rsp
+       subq    $216, %rsp
        .cfi_offset 15, -24
        .cfi_offset 14, -32
        .cfi_offset 13, -40
@@ -1337,19 +1337,15 @@
        movq    8(%rax), %rax
        movq    %rax, -72(%rbp)
        movq    -72(%rbp), %rax
-       movq    (%rax), %rdx
-       movq    _ZN7Sublime4Area9viewAddedEPNS_9AreaIndexEPNS_4ViewE@GOTPCREL(%rip), %rax
-       movq    %rax, %r8
-       movl    $0, %r9d
-       movq    %r8, %rax
-       cmpq    %rax, %rdx
+       movq    (%rax), %rax
+       testq   %rax, %rax
        jne     .L87
        movq    -72(%rbp), %rax
        movq    8(%rax), %rdx
        movq    _ZN7Sublime4Area9viewAddedEPNS_9AreaIndexEPNS_4ViewE@GOTPCREL(%rip), %rax
-       movq    %rax, %r10
-       movl    $0, %r11d
-       movq    %r11, %rax
+       movq    %rax, %r8
+       movl    $0, %r9d
+       movq    %r9, %rax
        cmpq    %rax, %rdx
        je      .L88
        movq    -72(%rbp), %rax
@@ -1362,19 +1358,15 @@
        jmp     .L55
 .L87:
        movq    -72(%rbp), %rax
-       movq    (%rax), %rdx
-       movq    _ZN7Sublime4Area17aboutToRemoveViewEPNS_9AreaIndexEPNS_4ViewE@GOTPCREL(%rip), %rax
-       movq    %rax, %r12
-       movl    $0, %r13d
-       movq    %r12, %rax
-       cmpq    %rax, %rdx
+       movq    (%rax), %rax
+       testq   %rax, %rax
        jne     .L89
        movq    -72(%rbp), %rax
        movq    8(%rax), %rdx
        movq    _ZN7Sublime4Area17aboutToRemoveViewEPNS_9AreaIndexEPNS_4ViewE@GOTPCREL(%rip), %rax
-       movq    %rax, %r14
-       movl    $0, %r15d
-       movq    %r15, %rax
+       movq    %rax, %r10
+       movl    $0, %r11d
+       movq    %r11, %rax
        cmpq    %rax, %rdx
        je      .L90
        movq    -72(%rbp), %rax
...
Comment 1 Markus Trippelsdorf 2016-09-28 12:35:27 UTC
Created attachment 39718 [details]
good assembly
Comment 2 Markus Trippelsdorf 2016-09-28 12:35:56 UTC
Created attachment 39719 [details]
bad assembly
Comment 3 Markus Trippelsdorf 2016-09-28 12:36:45 UTC
g++ -O0 -fPIC -c moc_area.ii -S -o bad_
Comment 4 Markus Trippelsdorf 2016-09-29 12:29:23 UTC
markus@x4 tmp % cat moc.ii
namespace Sublime {
struct View;
struct AreaIndex;
struct Area {
  void qt_static_metacall();
  void viewAdded(AreaIndex *, View *);
};
}
void Sublime::Area::qt_static_metacall() {
  typedef void (Area::*_t)(AreaIndex *, View *);
  if (*reinterpret_cast<_t *>(1) == _t(&Area::viewAdded))
    __builtin_abort();
}

gcc-6 -O3:

Sublime::Area::qt_static_metacall():
        cmpq    Sublime::Area::viewAdded(Sublime::AreaIndex*, Sublime::View*), 1
        je      .L7
.L1:
        rep ret
.L7:
        cmpq    $0, 9
        jne     .L1
        subq    $8, %rsp
        call    abort

trunk -O3:

Sublime::Area::qt_static_metacall():
        cmpq    $0, 1
        je      .L7
        rep ret
.L7:
        subq    $8, %rsp
        call    abort
Comment 5 Markus Trippelsdorf 2016-09-30 05:18:36 UTC
;; Function void Sublime::Area::qt_static_metacall() (null)
;; enabled by -tree-original


{
  typedef struct _t _t;

  if (1B->__pfn == ((struct _t) {.__pfn=viewAdded, .__delta=0}).__pfn && (1B->__delta == ((struct _t) {.__pfn=viewAdded, .__delta=0}).__delta || 1B->__pfn == 0B))
    {
      <<cleanup_point <<< Unknown tree: expr_stmt
  __builtin_abort () >>>>>;
    }
}

vs.

;; Function void Sublime::Area::qt_static_metacall() (null)
;; enabled by -tree-original


{
  typedef struct _t _t;

  if (1B->__pfn == 0B && (1B->__delta == ((struct _t) {.__pfn=viewAdded, .__delta=0}).__delta || 1B->__pfn == 0B))
    {
      <<cleanup_point <<< Unknown tree: expr_stmt
  __builtin_abort () >>>>>;
    }
}

Jason?
Comment 6 Jason Merrill 2016-10-04 21:14:50 UTC
Author: jason
Date: Tue Oct  4 21:14:18 2016
New Revision: 240757

URL: https://gcc.gnu.org/viewcvs?rev=240757&root=gcc&view=rev
Log:
	PR c++/77775 - misoptimization of PMF comparison

	* constexpr.c (cxx_eval_component_reference): Use name matching
	for PMFs.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-pmf1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
Comment 7 Jason Merrill 2016-10-04 21:15:02 UTC
Fixed.