public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic
@ 2022-09-14 20:31 eggert at cs dot ucla.edu
  2022-09-14 20:39 ` [Bug c/106947] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: eggert at cs dot ucla.edu @ 2022-09-14 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106947
           Summary: -Waddress + bool + pragma generates meaningless
                    diagnostic
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

I found this while testing Gnulib with gcc (GCC) 12.1.1 20220507 (Red Hat
12.1.1-1) on x86-64.

Compile the following with "gcc -Waddress -S t.c":

#pragma GCC diagnostic ignored "-Waddress"
int s;
_Bool e = &s;
int
main ()
{
  int error = 0;
  {
    _Bool e1 = &s;
    if (!e1)
      error = 1;
  }
  return error;
}

The output is the meaningless diagnostic:

t.c: In function ‘main’:
t.c:2:5: note: ‘s’ declared here
    2 | int s;
      |     ^

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

* [Bug c/106947] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
@ 2022-09-14 20:39 ` pinskia at gcc dot gnu.org
  2022-09-14 20:39 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-14 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The bug is in the C front-end.
Specifically the bug is in maybe_warn_for_null_address which does not check the
return value of warning if it should do the inform.

Something like this will fix the issue:
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index d37de2a313b..59e384ac997 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -11619,6 +11619,7 @@ build_vec_cmp (tree_code code, tree type,
 static void
 maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
 {
+  bool do_note = false;
   /* Prevent warnings issued for macro expansion.  */
   if (!warn_address
       || warning_suppressed_p (op, OPT_Waddress)
@@ -11706,17 +11707,17 @@ maybe_warn_for_null_address (location_t loc, tree op,
tree_code code)
     return;

   if (code == EQ_EXPR)
-    warning_at (loc, OPT_Waddress,
+    do_note = warning_at (loc, OPT_Waddress,
                "the comparison will always evaluate as %<false%> "
                "for the address of %qE will never be NULL",
                op);
   else
-    warning_at (loc, OPT_Waddress,
+    do_note = warning_at (loc, OPT_Waddress,
                "the comparison will always evaluate as %<true%> "
                "for the address of %qE will never be NULL",
                op);

-  if (DECL_P (op))
+  if (do_note && DECL_P (op))
     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
 }

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

* [Bug c/106947] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
  2022-09-14 20:39 ` [Bug c/106947] " pinskia at gcc dot gnu.org
@ 2022-09-14 20:39 ` pinskia at gcc dot gnu.org
  2022-09-14 20:42 ` [Bug c/106947] [12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-14 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-09-14

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
  2022-09-14 20:39 ` [Bug c/106947] " pinskia at gcc dot gnu.org
  2022-09-14 20:39 ` pinskia at gcc dot gnu.org
@ 2022-09-14 20:42 ` pinskia at gcc dot gnu.org
  2022-09-15  7:19 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-14 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|-Waddress + bool + pragma   |[12/13 Regression]
                   |generates meaningless       |-Waddress + bool + pragma
                   |diagnostic                  |generates meaningless
                   |                            |diagnostic
   Target Milestone|---                         |12.3

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is a regression from GCC 11.x which did not have this inform.
The inform was added in r12-4059-g4dc7ce6fb39179 .
What is interesting is the C++ front-end was done correctly but not the C
front-end ...

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (2 preceding siblings ...)
  2022-09-14 20:42 ` [Bug c/106947] [12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-09-15  7:19 ` rguenth at gcc dot gnu.org
  2022-09-15 15:19 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-15  7:19 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |easyhack
           Priority|P3                          |P2

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (3 preceding siblings ...)
  2022-09-15  7:19 ` rguenth at gcc dot gnu.org
@ 2022-09-15 15:19 ` mpolacek at gcc dot gnu.org
  2022-09-19 18:41 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-09-15 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (4 preceding siblings ...)
  2022-09-15 15:19 ` mpolacek at gcc dot gnu.org
@ 2022-09-19 18:41 ` cvs-commit at gcc dot gnu.org
  2022-09-19 18:43 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-19 18:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:2d9429d5c0f86f588bdfd85bb9e236d2be367d3f

commit r13-2723-g2d9429d5c0f86f588bdfd85bb9e236d2be367d3f
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Sep 19 14:12:55 2022 -0400

    c: Stray inform note with -Waddress [PR106947]

    A trivial fix for maybe_warn_for_null_address where we print an
    inform note without first checking the return value of a warning
    call.

            PR c/106947

    gcc/c/ChangeLog:

            * c-typeck.cc (maybe_warn_for_null_address): Don't emit stray
            notes.

    gcc/testsuite/ChangeLog:

            * c-c++-common/Waddress-7.c: New test.

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (5 preceding siblings ...)
  2022-09-19 18:41 ` cvs-commit at gcc dot gnu.org
@ 2022-09-19 18:43 ` cvs-commit at gcc dot gnu.org
  2022-09-19 18:43 ` mpolacek at gcc dot gnu.org
  2023-03-16 12:25 ` marxin at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-19 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:97803ee561c7a2692a6d7863a5d86797d79a18b1

commit r12-8774-g97803ee561c7a2692a6d7863a5d86797d79a18b1
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Sep 19 14:12:55 2022 -0400

    c: Stray inform note with -Waddress [PR106947]

    A trivial fix for maybe_warn_for_null_address where we print an
    inform note without first checking the return value of a warning
    call.

            PR c/106947

    gcc/c/ChangeLog:

            * c-typeck.cc (maybe_warn_for_null_address): Don't emit stray
            notes.

    gcc/testsuite/ChangeLog:

            * c-c++-common/Waddress-7.c: New test.

    (cherry picked from commit 2d9429d5c0f86f588bdfd85bb9e236d2be367d3f)

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (6 preceding siblings ...)
  2022-09-19 18:43 ` cvs-commit at gcc dot gnu.org
@ 2022-09-19 18:43 ` mpolacek at gcc dot gnu.org
  2023-03-16 12:25 ` marxin at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-09-19 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

* [Bug c/106947] [12/13 Regression] -Waddress + bool + pragma generates meaningless diagnostic
  2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
                   ` (7 preceding siblings ...)
  2022-09-19 18:43 ` mpolacek at gcc dot gnu.org
@ 2023-03-16 12:25 ` marxin at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-03-16 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bruno at clisp dot org

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
*** Bug 109155 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2023-03-16 12:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 20:31 [Bug middle-end/106947] New: -Waddress + bool + pragma generates meaningless diagnostic eggert at cs dot ucla.edu
2022-09-14 20:39 ` [Bug c/106947] " pinskia at gcc dot gnu.org
2022-09-14 20:39 ` pinskia at gcc dot gnu.org
2022-09-14 20:42 ` [Bug c/106947] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-09-15  7:19 ` rguenth at gcc dot gnu.org
2022-09-15 15:19 ` mpolacek at gcc dot gnu.org
2022-09-19 18:41 ` cvs-commit at gcc dot gnu.org
2022-09-19 18:43 ` cvs-commit at gcc dot gnu.org
2022-09-19 18:43 ` mpolacek at gcc dot gnu.org
2023-03-16 12:25 ` marxin 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).