From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2FFCD3858C98; Sat, 16 Mar 2024 17:27:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FFCD3858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710610075; bh=d4b6vEd3qz3akBy2rbpUTfs4wzWJ8Y3eTWjkseOJQRs=; h=From:To:Subject:Date:From; b=Qy/BYYciVn0yJzP9o4BkZmhPRksKQkSnwOw9bRO42/0JhHyoxzee+b50xBLM5SfCm SlI06yaUlXvFpkTTYgtYBHTE/WV22t//bAu61GDQxTxEo8GPsBSoIIkTD2NWYliZ28 9CkG+bu59VYlM4jDR/SwyH447Qif403sDwyF7tu4= From: "godmar at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114366] New: computed labels do not reflect true values of instruction pointer ranges when function is inlined Date: Sat, 16 Mar 2024 17:27:54 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: godmar at gmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114366 Bug ID: 114366 Summary: computed labels do not reflect true values of instruction pointer ranges when function is inlined Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: godmar at gmail dot com Target Milestone: --- Created attachment 57718 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D57718&action=3Dedit using labels as values example Hi, we recently got tripped up by the following: ```c #include void *beginPtr, *endPtr; int x; static void smallfunction(void) { beginPtr =3D &&begin; endPtr =3D &&end; begin: x++; end: } int main() { smallfunction(); assert(beginPtr < endPtr); } ``` When compiled with `-O0`, this program completes successfully. When compiled with `-O2`, this program fails its assertion because the following assembly code is produced: ``` .L2: .L3: leaq .L2(%rip), %rdx leaq .L3(%rip), %rax addl $1, x(%rip) ``` which IMO should be something like: ``` .L2: leaq .L2(%rip), %rdx leaq .L3(%rip), %rax addl $1, x(%rip) .L3: ``` I understand that using labels as values is a GCC extension, and I have read the comment in the documentation [1] that warns that &&foo might have a different value if a function is inlined. (Adding the noinline attribute f= ixes the problem at the cost of some performance.) Also note that "different values" is not the same as not being computed correctly. We encountered this problem building an exception handler. I will note that gcc will not inline the function if the computed values are actually used in a goto statement; when trying to force it to inline it, it throws an error. Is this a bug, or undocumented behavior? Perhaps the documentation should be clarified.=20=20 [1] https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html=