public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/112296] __builtin_constant_p doesn't propagate through member functions
Date: Tue, 31 Oct 2023 09:29:05 +0000	[thread overview]
Message-ID: <bug-112296-4-f7B9p4H6Ep@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112296-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |documentation
                 CC|                            |jsm28 at gcc dot gnu.org,
                   |                            |rth at gcc dot gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
+FAIL: gcc.c-torture/execute/bcp-1.c   -O1  (test for excess errors)
+UNRESOLVED: gcc.c-torture/execute/bcp-1.c   -O1  compilation failed to produce 
executable

that's because

bcp-1.c:(.text+0x6c): undefined reference to `func'^M
collect2: error: ld returned 1 exit status^M

the testcase can be reduced to

int func(void);
int bad7(void) { return __builtin_constant_p(func()); } 

and we want the side-effect to disappear!?  There's more fun in this testcase,
like verifying that

int bad1(void) { return __builtin_constant_p(global++); }

returns 0 (but not verifying whether 'global' is altered or not).

I don't see it documented that __builtin_constant_p discards side-effects on
operands - that would in fact make it behave like 'constexpr'?!

commit 54303b5cb3076f7bae9102c08b59d57b1a9f5104
Author: Richard Henderson <rth@cygnus.com>
Date:   Tue Jul 7 06:41:17 1998 -0700

    * gcc.c-torture/execute/bcp-1.c: New test.

So this also becomes a documentation thing and I doubt we can start to
retain side-effects we've thrown away for decades now.  But then
relying on _folding_ to implement what becomes a language extension this
way is definitely error-prone and fragile.

I think we should also definitely diagnose this somehow (which would also
mean moving discarding of side-effects to the frontend(s)).

Joseph, Richard, do you have anything to add or remember discussions about
this semantic detail of __builtin_constant_p?

  parent reply	other threads:[~2023-10-31  9:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30 14:22 [Bug c++/112296] New: " barry.revzin at gmail dot com
2023-10-30 14:26 ` [Bug c++/112296] " rguenth at gcc dot gnu.org
2023-10-30 14:46 ` redi at gcc dot gnu.org
2023-10-30 14:49 ` redi at gcc dot gnu.org
2023-10-31  8:29 ` [Bug tree-optimization/112296] " rguenth at gcc dot gnu.org
2023-10-31  9:29 ` rguenth at gcc dot gnu.org [this message]
2023-10-31  9:36 ` rguenth at gcc dot gnu.org
2023-10-31 13:51 ` rth at gcc dot gnu.org
2023-10-31 13:57 ` rguenth at gcc dot gnu.org
2023-10-31 14:05 ` rth at gcc dot gnu.org
2023-10-31 14:13 ` rguenth at gcc dot gnu.org
2023-10-31 14:23 ` rguenth at gcc dot gnu.org
2023-10-31 16:55 ` joseph at codesourcery dot com
2023-11-03  7:11 ` rguenth at gcc dot gnu.org
2023-11-06  7:27 ` cvs-commit at gcc dot gnu.org
2023-11-06  7:38 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-112296-4-f7B9p4H6Ep@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).