public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
@ 2021-08-09 18:25 pinskia at gcc dot gnu.org
2021-08-09 18:25 ` [Bug c++/101833] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09 18:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Bug ID: 101833
Summary: [9/10/11/12 Regression] ICE with -Wformat on a
constructor with a virtual base
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
class Base {};
struct VDerived : virtual Base
{
VDerived(int x, const char * f, ...)
__attribute__((format(printf, 5, 6)));
} a(1, "%s %d", "foo", 1);
----- CUT ----
We get an ICE:
<source>:5:26: warning: 'format' attribute argument 2 value '5' exceeds the
number of function parameters 3 [-Wattributes]
5 | } a(1, "%s %d", "foo", 1);
| ^
<source>:5:26: internal compiler error: in get_constant, at
c-family/c-format.c:325
0x1dbb089 internal_error(char const*, ...)
This started in 9.1.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
@ 2021-08-09 18:25 ` pinskia at gcc dot gnu.org
2021-08-10 7:34 ` marxin at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09 18:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |9.1.0
Target Milestone|--- |9.5
Known to work| |8.5.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
2021-08-09 18:25 ` [Bug c++/101833] " pinskia at gcc dot gnu.org
@ 2021-08-10 7:34 ` marxin at gcc dot gnu.org
2021-08-12 23:38 ` msebor at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-10 7:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org,
| |msebor at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-10
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r9-4163-g1d24950977c730f5.
What's strange that one needs '-Wall' in order to trigger the warning.
-Wattributes is not enough, is it correct Martin?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
2021-08-09 18:25 ` [Bug c++/101833] " pinskia at gcc dot gnu.org
2021-08-10 7:34 ` marxin at gcc dot gnu.org
@ 2021-08-12 23:38 ` msebor at gcc dot gnu.org
2022-01-17 13:57 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-12 23:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.3.0, 11.2.0, 12.0
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning is issued when the declaration is seen (either with -Wall or with
just -Wattributes). The ICE is a side-effect of -Wformat checking calls to the
function.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2021-08-12 23:38 ` msebor at gcc dot gnu.org
@ 2022-01-17 13:57 ` rguenth at gcc dot gnu.org
2022-03-31 22:02 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-17 13:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2022-01-17 13:57 ` rguenth at gcc dot gnu.org
@ 2022-03-31 22:02 ` mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` [Bug c++/101833] [9/10/11/12/13 " cvs-commit at gcc dot gnu.org
2022-05-07 14:59 ` [Bug c++/101833] [9/10/11/12 " mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-31 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12/13 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2022-03-31 22:02 ` mpolacek at gcc dot gnu.org
@ 2022-05-07 14:44 ` cvs-commit at gcc dot gnu.org
2022-05-07 14:59 ` [Bug c++/101833] [9/10/11/12 " mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-07 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
--- 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:0c723bb4be2a67657828b692997855afcdc5d286
commit r13-167-g0c723bb4be2a67657828b692997855afcdc5d286
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Mar 31 18:31:39 2022 -0400
c, c++: attribute format on a ctor with a vbase [PR101833, PR47634]
Attribute format takes three arguments: archetype, string-index, and
first-to-check. The last two specify the position in the function
parameter list. r63030 clarified that "Since non-static C++ methods have
an implicit this argument, the arguments of such methods should be counted
from two, not one, when giving values for string-index and first-to-check."
Therefore one has to write
struct D {
D(const char *, ...) __attribute__((format(printf, 2, 3)));
};
However -- and this is the problem in this PR -- ctors with virtual
bases also get two additional parameters: the in-charge parameter and
the VTT parameter (added in maybe_retrofit_in_chrg). In fact we'll end up
with two clones of the ctor: an in-charge and a not-in-charge version (see
build_cdtor_clones). That means that the argument position the user
specified in the attribute argument will refer to different arguments,
depending on which constructor we're currently dealing with. This can
cause a range of problems: wrong errors, confusing warnings, or crashes.
This patch corrects that; for C we don't have to do anything, and in C++
we can use num_artificial_parms_for. It would be wrong to rewrite the
attributes the user supplied, so I've changed POS to be passed by
reference so that we don't have to change all the call sites of
positional_argument and we still get the default_conversion adjustment.
Attribute format_arg is not affected, because it requires that the
function returns "const char *" which will never be the case for cdtors.
PR c++/101833
PR c++/47634
gcc/c-family/ChangeLog:
* c-attribs.cc (positional_argument): Pass POS by reference. Deal
with FN being either a function declaration or function type. Use
maybe_adjust_arg_pos_for_attribute.
* c-common.cc (check_function_arguments): Maybe pass FNDECL down to
check_function_format.
* c-common.h (maybe_adjust_arg_pos_for_attribute): Declare.
(positional_argument): Adjust.
* c-format.cc (get_constant): Rename to ...
(validate_constant): ... this. Take EXPR by reference. Return
bool
instead of tree.
(handle_format_arg_attribute): Don't overwrite FORMAT_NUM_EXPR by
the
return value of validate_constant.
(decode_format_attr): Don't overwrite FORMAT_NUM_EXPR and
FIRST_ARG_NUM_EXPR by the return value of validate_constant.
(check_function_format): Adjust a parameter name.
(handle_format_attribute): Maybe pass FNDECL down to
decode_format_attr.
gcc/c/ChangeLog:
* c-objc-common.cc (maybe_adjust_arg_pos_for_attribute): New.
gcc/cp/ChangeLog:
* tree.cc (maybe_adjust_arg_pos_for_attribute): New.
gcc/ChangeLog:
* tree-core.h (struct attribute_spec): Update comment for HANDLER.
gcc/testsuite/ChangeLog:
* g++.dg/ext/attr-format-arg1.C: New test.
* g++.dg/ext/attr-format1.C: New test.
* g++.dg/ext/attr-format2.C: New test.
* g++.dg/ext/attr-format3.C: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/101833] [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
` (5 preceding siblings ...)
2022-05-07 14:44 ` [Bug c++/101833] [9/10/11/12/13 " cvs-commit at gcc dot gnu.org
@ 2022-05-07 14:59 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-07 14:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101833
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12/13 Regression] |[9/10/11/12 Regression] ICE
|ICE with -Wformat on a |with -Wformat on a
|constructor with a virtual |constructor with a virtual
|base |base
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13. I don't have plans to backport this.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-07 14:59 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 18:25 [Bug c++/101833] New: [9/10/11/12 Regression] ICE with -Wformat on a constructor with a virtual base pinskia at gcc dot gnu.org
2021-08-09 18:25 ` [Bug c++/101833] " pinskia at gcc dot gnu.org
2021-08-10 7:34 ` marxin at gcc dot gnu.org
2021-08-12 23:38 ` msebor at gcc dot gnu.org
2022-01-17 13:57 ` rguenth at gcc dot gnu.org
2022-03-31 22:02 ` mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` [Bug c++/101833] [9/10/11/12/13 " cvs-commit at gcc dot gnu.org
2022-05-07 14:59 ` [Bug c++/101833] [9/10/11/12 " mpolacek 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).