public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug testsuite/109146] New: Tail call prevention in frame-address.c is not correct
@ 2023-03-15 15:44 david.spickett at linaro dot org
  2023-03-15 15:45 ` [Bug testsuite/109146] " david.spickett at linaro dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: david.spickett at linaro dot org @ 2023-03-15 15:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109146

            Bug ID: 109146
           Summary: Tail call prevention in frame-address.c is not correct
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: testsuite
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.spickett at linaro dot org
  Target Milestone: ---

With recent changes over in clang, it's now able to see through the tail call
prevention used in
https://github.com/gcc-mirror/gcc/blob/master/gcc/testsuite/gcc.c-torture/execute/frame-address.c.

The fix is pretty simple, `==` instead of `!=` will prevent the tail call.

Briefly, clang is now able to work out that if the called function returns 0,
the caller also returns 0, same for 1. Therefore, you can tail call the callee.

check_fa_work returns 0, 0 != 0 is False, so check_fa_mid returns 0
check_fa_work returns 1, 1 != 0 is True, so check_fa_mid returns 1

As far as I can tell, gcc does not do this, yet:
https://godbolt.org/z/v36zGP7f3

So it's worth fixing before gcc also starts to do this.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug testsuite/109146] Tail call prevention in frame-address.c is not correct
  2023-03-15 15:44 [Bug testsuite/109146] New: Tail call prevention in frame-address.c is not correct david.spickett at linaro dot org
@ 2023-03-15 15:45 ` david.spickett at linaro dot org
  2023-03-16 10:58 ` david.spickett at linaro dot org
  2023-12-06 18:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: david.spickett at linaro dot org @ 2023-03-15 15:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109146

--- Comment #1 from David Spickett <david.spickett at linaro dot org> ---
Correction. https://godbolt.org/z/fW5nsWE5e shows the issue when "!=" is used,
the previous link used "==" instead.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug testsuite/109146] Tail call prevention in frame-address.c is not correct
  2023-03-15 15:44 [Bug testsuite/109146] New: Tail call prevention in frame-address.c is not correct david.spickett at linaro dot org
  2023-03-15 15:45 ` [Bug testsuite/109146] " david.spickett at linaro dot org
@ 2023-03-16 10:58 ` david.spickett at linaro dot org
  2023-12-06 18:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: david.spickett at linaro dot org @ 2023-03-16 10:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109146

--- Comment #2 from David Spickett <david.spickett at linaro dot org> ---
A detail that might be useful. The callee function uses UB because it compares
pointers that don't point to the same object.

https://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf 6.5.8 Relational
operators, if we follow item 6, I think we end up at "In all other cases, the
behavior is undefined.".

So if codegen changes for the tail call you may need to double check that the
UB is still doing the same as before.

(it being UB at all seems fine, I don't know how else you'd check the address
of stack frames)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug testsuite/109146] Tail call prevention in frame-address.c is not correct
  2023-03-15 15:44 [Bug testsuite/109146] New: Tail call prevention in frame-address.c is not correct david.spickett at linaro dot org
  2023-03-15 15:45 ` [Bug testsuite/109146] " david.spickett at linaro dot org
  2023-03-16 10:58 ` david.spickett at linaro dot org
@ 2023-12-06 18:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-06 18:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109146

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
noipa was added in r14-5628-g53ba8d669550d3 to avoid the IPA VRP return.

So fixed from GCC's point of view.  Yes noipa is not implemented in clang/LLVM
but the testcase is a GCC testcase after all.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-06 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 15:44 [Bug testsuite/109146] New: Tail call prevention in frame-address.c is not correct david.spickett at linaro dot org
2023-03-15 15:45 ` [Bug testsuite/109146] " david.spickett at linaro dot org
2023-03-16 10:58 ` david.spickett at linaro dot org
2023-12-06 18:59 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).