public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/112701] New: wrong type inference for ternary operator in preprocessing context
@ 2023-11-24 14:56 amonakov at gcc dot gnu.org
  2023-11-24 15:46 ` [Bug preprocessor/112701] wrong type inference for ternary operator with `0/0u` " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-11-24 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112701
           Summary: wrong type inference for ternary operator in
                    preprocessing context
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amonakov at gcc dot gnu.org
  Target Milestone: ---

In the following snippet, the result of the ternary operator is (-1, cast to an
unsigned type), so the comparison yields false, and both conditional inclusions
must come out empty:

#if (0 ? 0u : -1) < 0
int foo = (0 ? 0u : -1) < 0;
#endif

#if (0 ? 0/0u : -1) < 0
int bar = (0 ? 0/0u : -1) < 0;
#endif

However, GCC emits:

bar:
        .zero   4

So clearly the evaluation of the second expression is inconsistent between
preprocessing context (where it incorrectly yields 1) vs. initializer context
(where it is zero as it should be, as seen from the resulting asm).

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

end of thread, other threads:[~2023-11-28  6:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 14:56 [Bug preprocessor/112701] New: wrong type inference for ternary operator in preprocessing context amonakov at gcc dot gnu.org
2023-11-24 15:46 ` [Bug preprocessor/112701] wrong type inference for ternary operator with `0/0u` " pinskia at gcc dot gnu.org
2023-11-25 17:06 ` mikpelinux at gmail dot com
2023-11-27  7:56 ` rguenth at gcc dot gnu.org
2023-11-27 17:56 ` lhyatt at gcc dot gnu.org
2023-11-27 18:02 ` pinskia at gcc dot gnu.org
2023-11-28  0:14 ` lhyatt at gcc dot gnu.org
2023-11-28  2:44 ` cvs-commit at gcc dot gnu.org
2023-11-28  2:45 ` lhyatt at gcc dot gnu.org
2023-11-28  6:54 ` sjames 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).