[Bug c/101538] New: [10/11/12 Regression] #pragma considered a statement
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 20 19:39:50 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101538
Bug ID: 101538
Summary: [10/11/12 Regression] #pragma considered a statement
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In the following test case both #pragma directives are expected to be evaluated
at compile-time with no effect on the emitted object code. Since the
conditional evaluates to zero the call to abort is expected to be eliminated.
Yet the emitted code shows that GCC treats the first #pragma as the empty
statement, thus ending the if statement. The end result is that the abort call
is made unconditionally. In the second instance, the unknown #pragma is
ignored and the code behaves as expected. That there's a difference between
the two is only hinted on by the -Wunknown-pragmas warning when it's enabled.
Clang and ICC behave as expected, as does G++ and GCC 4.1 (which doesn't
recognize #pragma message).
This was noticed when using #pragma GCC diagnostic and noted here:
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/575613.html
$ cat a.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
void f (void)
{
if (""['\0'])
#pragma message "Gotcha!"
__builtin_abort ();
}
void g (void)
{
if (""['\0'])
#pragma "Okay"
__builtin_abort ();
}
a.c: In function ‘f’:
a.c:4:9: note: ‘#pragma message: Gotcha!’
4 | #pragma message "Gotcha!"
| ^~~~~~~
a.c: In function ‘g’:
a.c:11: warning: ignoring ‘#pragma "Okay" ’ [-Wunknown-pragmas]
11 | #pragma "Okay"
|
;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)
(unlikely executed)
void f ()
{
<bb 2> [count: 0]:
__builtin_abort ();
}
;; Function g (g, funcdef_no=1, decl_uid=1946, cgraph_uid=2, symbol_order=1)
void g ()
{
<bb 2> [local count: 1073741824]:
return;
}
More information about the Gcc-bugs
mailing list