public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99156] New: __builtin_expect affects the interpretation of its first operand
@ 2021-02-19  4:29 zhan3299 at purdue dot edu
  2021-02-19 15:15 ` [Bug c/99156] " marxin at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zhan3299 at purdue dot edu @ 2021-02-19  4:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99156
           Summary: __builtin_expect affects the interpretation of its
                    first operand
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhan3299 at purdue dot edu
  Target Milestone: ---

I hope it does not bother. I try to refer to a bug in llvm which may also
affect gcc.  

Following are copied-and-pasted from the discussion about a similar bug in
clang (https://bugs.llvm.org/show_bug.cgi?id=49239#c3). 

Specifically, 

> int maybe_vla(int n) {
>    goto label;
>    int arr[({0;})];
> label:
>    return sizeof(arr);
> }
> 
> ... is rejected by both Clang and GCC because the statement-expression is not an ICE, but
> 
> int maybe_vla(int n) {
>     goto label;
>     int arr[__builtin_expect(({0;}), 0)];
> label:
>     return sizeof(arr);
> }
> 
> ... is accepted. This seems like a bug in both compilers to me: __builtin_expect isn't supposed to affect the interpretation of its first operand, and presumably shouldn't be weakening the strict ICE checks.


case 1: https://godbolt.org/z/zWGEfx
case 2: https://godbolt.org/z/bejfcc

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

* [Bug c/99156] __builtin_expect affects the interpretation of its first operand
  2021-02-19  4:29 [Bug c/99156] New: __builtin_expect affects the interpretation of its first operand zhan3299 at purdue dot edu
@ 2021-02-19 15:15 ` marxin at gcc dot gnu.org
  2021-02-19 21:32 ` zhan3299 at purdue dot edu
  2021-07-23 18:18 ` [Bug c/99156] __builtin_expect is folded too soon allowing an non-integer-constant-expr to become an integer-const-expr pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-19 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-02-19
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Yes, I can confirm the issue. Thanks for the report.

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

* [Bug c/99156] __builtin_expect affects the interpretation of its first operand
  2021-02-19  4:29 [Bug c/99156] New: __builtin_expect affects the interpretation of its first operand zhan3299 at purdue dot edu
  2021-02-19 15:15 ` [Bug c/99156] " marxin at gcc dot gnu.org
@ 2021-02-19 21:32 ` zhan3299 at purdue dot edu
  2021-07-23 18:18 ` [Bug c/99156] __builtin_expect is folded too soon allowing an non-integer-constant-expr to become an integer-const-expr pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: zhan3299 at purdue dot edu @ 2021-02-19 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from zhan3299 at purdue dot edu ---
(In reply to Martin Liška from comment #1)
> Yes, I can confirm the issue. Thanks for the report.

Many thanks for your prompt reply. Additionally, I have to give credit to
Richard Smith for finding the root cause.

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

* [Bug c/99156] __builtin_expect is folded too soon allowing an non-integer-constant-expr to become an integer-const-expr
  2021-02-19  4:29 [Bug c/99156] New: __builtin_expect affects the interpretation of its first operand zhan3299 at purdue dot edu
  2021-02-19 15:15 ` [Bug c/99156] " marxin at gcc dot gnu.org
  2021-02-19 21:32 ` zhan3299 at purdue dot edu
@ 2021-07-23 18:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-23 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|__builtin_expect affects    |__builtin_expect is folded
                   |the interpretation of its   |too soon allowing an
                   |first operand               |non-integer-constant-expr
                   |                            |to become an
                   |                            |integer-const-expr
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is another example which shows the problem even further:
int maybe_vla(int n) {
    goto label;
    int arr[__builtin_expect(n-n, 0)];
label:
    return sizeof(arr);
}

int main() { return maybe_vla(0); }

---- CUT ----
Basically __builtin_expect is folded too soon which allows the argument to be
considered a constant integer expression :).

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

end of thread, other threads:[~2021-07-23 18:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19  4:29 [Bug c/99156] New: __builtin_expect affects the interpretation of its first operand zhan3299 at purdue dot edu
2021-02-19 15:15 ` [Bug c/99156] " marxin at gcc dot gnu.org
2021-02-19 21:32 ` zhan3299 at purdue dot edu
2021-07-23 18:18 ` [Bug c/99156] __builtin_expect is folded too soon allowing an non-integer-constant-expr to become an integer-const-expr 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).