public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
@ 2022-01-20 18:14 jakub at gcc dot gnu.org
  2022-01-20 18:15 ` [Bug c++/104148] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104148
           Summary: [11/12 Regression] -Wformat warning no longer warns
                    about () wrapped args since r11-2457
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

Since r11-2457-gdf5cf47a978aaeb53fc2b18ff0b22eb4531a27d8 we get with -Wformat
just 14 warnings in C++ instead of 24 that were reported before that commit and
that are reported by C.
char *foo (const char *) __attribute__((format_arg(1)));
void bar (const char *, ...) __attribute__((format(printf, 1, 2)));

void
baz (int x)
{
  bar ("%ld", x);
  bar (x ? "%ld" : "%ld", x);
  bar (x ? "%ld" : "%lld", x);
  bar (foo ("%ld"), x);
  bar (x ? foo ("%ld") : "%ld", x);
  bar (x ? foo ("%ld") : "%lld", x);
  bar (foo (x ? "%ld" : "%ld"), x);
  bar (foo (x ? "%ld" : "%lld"), x);
  bar (("%ld"), x);
  bar ((x ? "%ld" : "%ld"), x);
  bar ((x ? "%ld" : "%lld"), x);
  bar ((foo ("%ld")), x);
  bar ((x ? foo ("%ld") : "%ld"), x);
  bar ((x ? foo ("%ld") : "%lld"), x);
  bar ((foo (x ? "%ld" : "%ld")), x);
  bar ((foo (x ? "%ld" : "%lld")), x);
}

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
@ 2022-01-20 18:15 ` jakub at gcc dot gnu.org
  2022-01-20 18:18 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 18:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
   Target Milestone|---                         |11.3
           Priority|P3                          |P2

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
  2022-01-20 18:15 ` [Bug c++/104148] " jakub at gcc dot gnu.org
@ 2022-01-20 18:18 ` jakub at gcc dot gnu.org
  2022-01-20 18:50 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
check_function_arguments_recurse does multiple things, but I think -Wformat
when discovering the string literals shouldn't really care whether
TREE_NO_WARNING is set or not, the warning should be driven by TREE_NO_WARNING
on the CALL_EXPR to the function with format attribute.

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
  2022-01-20 18:15 ` [Bug c++/104148] " jakub at gcc dot gnu.org
  2022-01-20 18:18 ` jakub at gcc dot gnu.org
@ 2022-01-20 18:50 ` jakub at gcc dot gnu.org
  2022-01-20 19:01 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 18:50 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-01-20
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-01-20 18:50 ` jakub at gcc dot gnu.org
@ 2022-01-20 19:01 ` jakub at gcc dot gnu.org
  2022-01-20 19:11 ` msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52245
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52245&action=edit
gcc12-pr104148.patch

Untested fix.

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-01-20 19:01 ` jakub at gcc dot gnu.org
@ 2022-01-20 19:11 ` msebor at gcc dot gnu.org
  2022-01-20 19:49 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-20 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
I suspect the unwanted suppression is because check_function_argument_recurse()
calls warning_suppressed_p (param) instead of warning_suppressed_p (param,
<option>) (for each of the warnings it checks).  So any other warning
suppressed for a call (or its arguments) like -Wparentheses will also suppress
-Wformat and friends.

Or it could also be because of one the outstanding suppress_warning() calls
with no warning option id:

grep suppress_warning gcc/cp/*.cc | grep -v OPT)
gcc/cp/call.cc: suppress_warning (c /* Suppress all warnings.  */);
gcc/cp/call.cc:      suppress_warning (decl);
gcc/cp/constraint.cc:   suppress_warning (t);
gcc/cp/coroutines.cc:  suppress_warning (r); /* We don't want a warning about
this.  */
gcc/cp/coroutines.cc:  suppress_warning (r); /* We don't want a warning about
this.  */
gcc/cp/coroutines.cc:      suppress_warning (rethrow);
gcc/cp/coroutines.cc:      suppress_warning (rethrow);
gcc/cp/cp-gimplify.cc:  suppress_warning (*stmt_p);
gcc/cp/cp-gimplify.cc:  suppress_warning (TREE_OPERAND (*stmt_p, 1));
gcc/cp/except.cc:      suppress_warning (rethrow);
gcc/cp/init.cc:   suppress_warning (cleanup);
gcc/cp/init.cc:   suppress_warning (init_expr);
gcc/cp/init.cc:      suppress_warning (stmt_expr /* What warning? */);
gcc/cp/pt.cc:      suppress_warning (tldcl);
gcc/cp/semantics.cc:    suppress_warning (DECL_EXPR_DECL (data.stmts[0]) /*
What warning? */);
gcc/cp/semantics.cc:    suppress_warning (DECL_EXPR_DECL (data.stmts[0])  /*
Wat warning? */);
gcc/cp/typeck.cc:      suppress_warning (arg /* What warning? */);
gcc/cp/typeck.cc:         suppress_warning (rval /* What warning? */);

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-01-20 19:11 ` msebor at gcc dot gnu.org
@ 2022-01-20 19:49 ` jakub at gcc dot gnu.org
  2022-01-21 21:45 ` cvs-commit at gcc dot gnu.org
  2022-01-21 21:47 ` [Bug c++/104148] [11 " jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-20 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52247
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52247&action=edit
gcc12-pr104148.patch

I guess I could use opt_code instead of bool, but
1) I think we still want not to bother with warning_suppressed_p at all for
-Wformat*, for one there are various warning options affected, and as I said,
it isn't warning at all, it is looking for the argument value
2) passing that for -Wnonnull is deferred for later

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

* [Bug c++/104148] [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-01-20 19:49 ` jakub at gcc dot gnu.org
@ 2022-01-21 21:45 ` cvs-commit at gcc dot gnu.org
  2022-01-21 21:47 ` [Bug c++/104148] [11 " jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-21 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:f36efe71bef8ddf72306aca313d28759434cf97a

commit r12-6810-gf36efe71bef8ddf72306aca313d28759434cf97a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jan 21 22:44:53 2022 +0100

    c-family: Fix up a -Wformat regression [PR104148]

    As can be seen on the testcase, GCC 11 no longer warns if the format
    string is wrapped inside of ()s.
    This regressed with r11-2457-gdf5cf47a978, which added
    if (TREE_NO_WARNING (param)) return;
    to check_function_arguments_recurse.  That function is used with a callback
    for two cases, for -Wformat and for -Wnonnull.  For the latter it is
    desirable to not warn in parameters or their subexpressions where that
    warning is suppressed, but for -Wformat the function is used solely
    to discover the string literals if any so that the c-format.cc code can
    diagnose them.  I believe no warning suppression should stand in the
    way of that, -Wformat* warnings should be decided from warning suppression
    on the CALL_EXPR only.
    In the PR Martin argued that now that we have specialized
    warning_suppressed_p we should use it, so instead of adding a bool
    arg to check_function_arguments_recurse I've added opt_code to the
    function, but will defer the warning_suppressed_p change to him.
    For OPT_Wformat_ we don't want to call it anyway at all (as I said,
    I think there should be no suppression for it during the string discovery,
    there isn't just one -Wformat= option, there are many and
    warning_suppression_p even with no_warnings actually tests the
    TREE_NO_WARNING bit).
    Initially, I thought I'd restrict also call to fn with format_arg attribute
    handling in check_function_arguments_recurse to OPT_Wformat_ only, but
    after looking around, it perhaps is intentional that way, most functions
    with format_arg attribute don't have nonnull attribute for that arg too,
    various gettext implementations handle NULL argument by passing it through,
    but when result of gettext (NULL) etc. is passed to non-NULL argument, it
    makes sense to warn.

    2022-01-21  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104148
            * c-common.h (check_function_arguments_recurse): Add for_format
            arg.
            * c-common.cc (check_function_nonnull): Pass false to
            check_function_arguments_recurse's last argument.
            (check_function_arguments_recurse): Add for_format argument,
            if true, don't stop on warning_suppressed_p.
            * c-format.cc (check_format_info): Pass true to
            check_function_arguments_recurse's last argument.

            * c-c++-common/Wformat-pr104148.c: New test.

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

* [Bug c++/104148] [11 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457
  2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-01-21 21:45 ` cvs-commit at gcc dot gnu.org
@ 2022-01-21 21:47 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-21 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|11.3                        |12.0
            Summary|[11/12 Regression] -Wformat |[11 Regression] -Wformat
                   |warning no longer warns     |warning no longer warns
                   |about () wrapped args since |about () wrapped args since
                   |r11-2457                    |r11-2457
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk, won't fix for 11, because the fix enables more warnings
than previously.

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

end of thread, other threads:[~2022-01-21 21:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 18:14 [Bug c++/104148] New: [11/12 Regression] -Wformat warning no longer warns about () wrapped args since r11-2457 jakub at gcc dot gnu.org
2022-01-20 18:15 ` [Bug c++/104148] " jakub at gcc dot gnu.org
2022-01-20 18:18 ` jakub at gcc dot gnu.org
2022-01-20 18:50 ` jakub at gcc dot gnu.org
2022-01-20 19:01 ` jakub at gcc dot gnu.org
2022-01-20 19:11 ` msebor at gcc dot gnu.org
2022-01-20 19:49 ` jakub at gcc dot gnu.org
2022-01-21 21:45 ` cvs-commit at gcc dot gnu.org
2022-01-21 21:47 ` [Bug c++/104148] [11 " jakub 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).