public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og
[not found] <bug-90710-4@http.gcc.gnu.org/bugzilla/>
@ 2021-04-06 23:13 ` msebor at gcc dot gnu.org
2021-04-06 23:16 ` msebor at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-06 23:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90710
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2019-06-02 00:00:00 |2021-4-6
Known to fail| |10.2.1, 11.0, 9.3.0
CC| |msebor at gcc dot gnu.org
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11. My enhanced version of trunk under test prints:
pr90710.c: In function ‘testFunction’:
pr90710.c:22:17: warning: ‘value’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
22 | printf("My if() causes -Wmaybe-uninitialized for my use
of `value': %d\n",value);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr90710.c:17:22: note: when ‘x == 0’
17 | unsigned int value;
| ^~~~~
pr90710.c:17:22: note: used when ‘_11 = PHI <0(3), 1(9)> != 0’
pr90710.c:17:22: note: ‘value’ was declared here
The IL the warning sees (annotated with my comments) is below. The predicate
that guards the possibly uninitialized use is (was_ok_8 != 0 && was_ok_8 == 0),
which the warning should be able to determine is false. It doesn't because, as
a result of the __builtin_expect() intrinsic which converts the first argument
to long int, the assignment 'was_ok_8 = (int) _11' in bb 4 involves a
conversion that the warning code doesn't handle. Changing the type of the
variables to long avoids the warning.
__attribute__((noinline))
void testFunction ()
{
int was_ok;
unsigned int value;
volatile unsigned int x;
unsigned int x.0_1;
long int _2;
unsigned int _11;
<bb 2> [local count: 1073741824]:
# .MEM_7 = VDEF <.MEM_6(D)>
x ={v} 1;
# VUSE <.MEM_7>
x.0_1 ={v} x;
if (x.0_1 == 0)
goto <bb 3>; [34.00%]
else
goto <bb 9>; [66.00%]
<bb 9> [local count: 708669600]:
goto <bb 4>; [100.00%]
<bb 3> [local count: 365072224]:
<bb 4> [local count: 1073741824]:
# _11 = PHI <0(3), 1(9)>
# value_12 = PHI <value_13(D)(3), x.0_1(9)>
was_ok_8 = (int) _11; <<< int to long conversion gets in the way
if (was_ok_8 != 0)
goto <bb 5>; [33.00%]
else
goto <bb 10>; [67.00%] <<< was_ok_8 == 0
<bb 10> [local count: 719407024]:
goto <bb 6>; [100.00%]
<bb 5> [local count: 354334800]:
# .MEM_9 = VDEF <.MEM_7>
printf ("My if() compiles fine: %d\n", value_12);
<bb 6> [local count: 1073741824]:
# .MEM_4 = PHI <.MEM_7(10), .MEM_9(5)>
_2 = (long int) was_ok_8;
if (_2 != 0)
goto <bb 7>; [90.00%] <<< was_ok_8 != 0
else
goto <bb 11>; [10.00%]
<bb 11> [local count: 107374184]:
goto <bb 8>; [100.00%]
<bb 7> [local count: 966367641]:
## value_12 used when was_ok_8 != 0 AND was_ok_8 == 0 <<< must be false
# .MEM_10 = VDEF <.MEM_4>
printf ("My if() causes -Wmaybe-uninitialized for my use of `value\': %d\n",
value_12);
<bb 8> [local count: 1073741824]:
# .MEM_5 = PHI <.MEM_4(11), .MEM_10(7)>
# VUSE <.MEM_5>
return;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og
[not found] <bug-90710-4@http.gcc.gnu.org/bugzilla/>
2021-04-06 23:13 ` [Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og msebor at gcc dot gnu.org
@ 2021-04-06 23:16 ` msebor at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-06 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90710
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Here's a smaller test case showing both the problem (first gcc invocation) and
how it can be avoided (second invocation):
$ (set -x && cat pr90710.c && gcc -Og -S -Wall pr90710.c && gcc -Dint=long -Og
-S -Wall pr90710.c)
+ cat pr90710.c
static inline int f (int x, int *p)
{
if (x == 0)
return 0;
*p = x;
return 1;
}
volatile int z;
void g (int x)
{
int b, a = f (x, &b);
if (a)
z = b;
if (__builtin_expect (a, 1))
z = b;
}
+ gcc -Og -S -Wall pr90710.c
pr90710.c: In function ‘g’:
pr90710.c:20:7: warning: ‘b’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
20 | z = b;
| ~~^~~
pr90710.c:14:7: note: ‘b’ was declared here
14 | int b, a = f (x, &b);
| ^
+ gcc -Dint=long -Og -S -Wall pr90710.c
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-06 23:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-90710-4@http.gcc.gnu.org/bugzilla/>
2021-04-06 23:13 ` [Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og msebor at gcc dot gnu.org
2021-04-06 23:16 ` msebor 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).