Bug 105628 - [12/13/14 Regression] False positive with -Waddress
Summary: [12/13/14 Regression] False positive with -Waddress
Status: RESOLVED DUPLICATE of bug 102967
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 12.1.1
: P2 normal
Target Milestone: 12.4
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, needs-bisection
: 114306 (view as bug list)
Depends on:
Blocks: Waddress
  Show dependency treegraph
 
Reported: 2022-05-17 12:32 UTC by J. Römmler
Modified: 2024-03-11 12:34 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
minified example program to show the false positive (768 bytes, text/x-csrc)
2022-05-17 12:32 UTC, J. Römmler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description J. Römmler 2022-05-17 12:32:59 UTC
Created attachment 52986 [details]
minified example program to show the false positive

Option -Wall also enables -Waddress, which causes a lot of false positives like shown in my attached example problem (minimized and anonymized real world example):

waddress.c: In function ‘comp_has_ExtraPtr’:
waddress.c:44:29: warning: the comparison will always evaluate as ‘true’ for the pointer operand in ‘(struct Extra **)&comp->pin + 4’ must not be NULL [-Waddress]
   44 |     return ExtraPtrOf(comp) ? 1 : 0;
      |                             ^

It only seems to be emitted when using the ?-operator.


# gcc -v
...
gcc version 12.1.1 20220507 (Red Hat 12.1.1-1) (GCC)


# uname -a
Linux fedora 5.17.6-300.fc36.x86_64 #1 SMP PREEMPT Mon May 9 15:47:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 Andrew Pinski 2022-05-17 12:44:26 UTC
The warning is correct but it should not be done.

Simpele testcase:
struct s{ int f; };
int g(struct s t){
  return (t.f?&t.f : 0)? 1 : 0;
}

The problem is gcc did some optimizations before the warning and pushed the implicit != 0 into each arm of the ?; operator
Comment 2 Richard Biener 2023-05-08 12:24:30 UTC
GCC 12.3 is being released, retargeting bugs to GCC 12.4.
Comment 3 Andrew Pinski 2024-03-11 12:32:48 UTC
*** Bug 114306 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2024-03-11 12:34:36 UTC
So it turns out the change for ?: to warn for -Waddress was done on purpose. See PR 102967  . PR 102967  is about the wrong location for the warning and such but it was originally about the same type of expression.

*** This bug has been marked as a duplicate of bug 102967 ***