From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 14FDF385DC00; Sat, 4 Apr 2020 15:33:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14FDF385DC00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586014396; bh=Lr1ecbrH7SkGYBK54SQ5aiaj+SG5gDZOO5T6cJ66wQw=; h=From:To:Subject:Date:From; b=gv1tTc+8yMGSriT3240p06KbMQl9kT7F4l7CyRjR6QDTfeNvHb2DL3jJsSgvkREwk mbc6ZsDfT2doses5Mtc8F54h+f7woWi8M/xwIZAeaG43LCHh1bDcaHljjQMGi/xeUu bdwnl0TmNunzp7g5nANFiCrODY96FVhMI7GXCMGU= From: "dimitri.gorokhovik at free dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/94485] New: [10.0.1, c++2a] g++ optimizes away the code, accepts arbitrary inline asm Date: Sat, 04 Apr 2020 15:33:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dimitri.gorokhovik at free dot fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Apr 2020 15:33:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94485 Bug ID: 94485 Summary: [10.0.1, c++2a] g++ optimizes away the code, accepts arbitrary inline asm Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dimitri.gorokhovik at free dot fr Target Milestone: --- Created attachment 48194 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48194&action=3Dedit Sample code illustrating the sighting. Version: gcc (GCC) 10.0.1 20200404 (experimental) command line: ~/gcc-trunk/dist/bin/g++ -std=3Dc++2a -O3 -Wall -Wextra -W bug-20200404170= 9.cpp -o bug-1 && ./bug-1 The attached file (apologies, still big) contains the following code (line 425): constexpr iterator (tesselation const& me) : cube_ { me.cube_ }, inner_ { me.as_parent ().begin () }, tess_ {}, outer_ { tess_ } { if (inner_) { tess_ =3D tesselation_of_two_cubes { cube_, *inner_ }; asm("before:"); #if 0 // breaks only with -O3 auto const tmp { tess_.begin () }; asm("middle:"); outer_ =3D tmp; ^^^^^^^^^^^^ #else // breaks with -O3, -O1, fixes with -fsanitize=3Dundefined|null outer_ =3D { tess_.begin () }; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ asm("after:"); #endif inner_.next (); if (! outer_) throw 749; }; }; (Minor remark: 'asm' statements in this constexpr method raise no brows. I tried putting there insns that require evaluation, seems anything is silent= ly accepted. The same asm statements are rejected in a more simple constexpr code.) It seems, some optimization levels completely remove the highlighted assign= ment so that 'throw 749' is executed (main() prints it then). Other passes keep = the copying code and produce expected result. This over-optimization can be fix= ed by enabling certain sanitizers: undefined, null, vptr. The asm code produced: -- broken (compiled with -O3 or -O1): #APP # 425 "bug-1.cpp" 1 before: # 0 "" 2 #NO_APP movq %r12, 216(%rsp) #APP # 433 "bug-1.cpp" 1 after: # 0 "" 2 #NO_APP -- working (compiled with -O0 or -O1 or with -fsanitizer=3Dnull): #APP # 425 "bug-1.cpp" 1 before: # 0 "" 2 #NO_APP xorl %eax, %eax cmpb $0, 43(%rbx) movq %r14, 64(%rsp) movw %ax, 72(%rsp) movb $0, 74(%rsp) je .L73 cmpb $0, 63(%rbx) je .L73 cmpb $0, 83(%rbx) sete %al .L68: movb %al, 75(%rsp) movq 64(%rsp), %rax movdqa 64(%rsp), %xmm6 movq %rax, 88(%rbx) movl 72(%rsp), %eax movaps %xmm6, 96(%rsp) movl %eax, 96(%rbx) #APP # 433 "bug-1.cpp" 1 after: # 0 "" 2 #NO_APP=