public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734
@ 2020-04-26 15:24 zhroma at gcc dot gnu.org
2020-04-26 19:34 ` [Bug tree-optimization/94775] " zhroma at gcc dot gnu.org
` (20 more replies)
0 siblings, 21 replies; 22+ messages in thread
From: zhroma at gcc dot gnu.org @ 2020-04-26 15:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Bug ID: 94775
Summary: [8/9/10 Regression] ICE in strip_typedefs, at
cp/tree.c:1734
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zhroma at gcc dot gnu.org
Target Milestone: ---
At least ubuntu v8.3.0 and trunk v10.0.1 (20200402) ICE on Linux x86-64 with
the following reduced testcase while emitting diagnostic:
$ cat bug.ii
template <typename> using a = int;
template <bool, typename, typename> using b = int;
typedef char d;
template <long> using e = int;
template <int f, int q> struct h { using i = b<q, a<e<f>>, e<f>>; };
template <long f, bool g> using j = typename h<f, g>::i;
long ab, k, aj;
const d l[]{};
class m {
public:
m(int);
};
class n {
m ad() const;
template <class ae> void o(long) const {
using c __attribute__((aligned(1))) = const ae;
}
long p;
template <class, class>
auto s(unsigned long, unsigned long, unsigned long, unsigned long) const;
template <bool = false> auto q(unsigned long, unsigned long) const;
};
template <class, class>
auto n::s(unsigned long, unsigned long, unsigned long, unsigned long t) const {
o<d>(p);
return t;
}
template <bool g> auto n::q(unsigned long p1, unsigned long p2) const {
using r = j<4, false>;
using ai = j<4, g>;
return s<ai, r>(ab, k, p1, p2);
}
m n::ad() const {
long f(l[aj]);
m(q(8, f));
}
$ g++ -std=c++17 -Wall -O2 -c -fsanitize=address bug.ii
bug.ii: In member function 'void n::o(long int) const':
bug.ii:16:11: warning: typedef 'using c = const ae' locally defined but not
used [-Wunused-local-typedefs]
16 | using c __attribute__((aligned(1))) = const ae;
| ^
bug.ii: In member function 'm n::ad() const':
bug.ii:36:1: warning: no return statement in function returning non-void
[-Wreturn-type]
36 | }
| ^
'
during GIMPLE pass: vrp
in strip_typedefs, at cp/tree.c:1734
33 | m n::ad() const {
| ^
0x9b4eeb strip_typedefs(tree_node*, bool*, unsigned int)
...
7.5.0 seems to work fine.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
@ 2020-04-26 19:34 ` zhroma at gcc dot gnu.org
2020-04-27 4:33 ` [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48 marxin at gcc dot gnu.org
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: zhroma at gcc dot gnu.org @ 2020-04-26 19:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #1 from Roman Zhuykov <zhroma at gcc dot gnu.org> ---
Additionally checked that vanilla gcc-9.3.0 version is also affected.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
2020-04-26 19:34 ` [Bug tree-optimization/94775] " zhroma at gcc dot gnu.org
@ 2020-04-27 4:33 ` marxin at gcc dot gnu.org
2020-04-27 6:44 ` rguenth at gcc dot gnu.org
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-04-27 4:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |ice-on-valid-code
Last reconfirmed| |2020-04-27
CC| |marxin at gcc dot gnu.org,
| |msebor at gcc dot gnu.org
Known to work| |7.4.0
Target Milestone|--- |8.5
Status|UNCONFIRMED |NEW
Known to fail| |10.0, 8.3.0, 9.2.0
Summary|[8/9/10 Regression] ICE in |[8/9/10 Regression] ICE in
|strip_typedefs, at |strip_typedefs, at
|cp/tree.c:1734 |cp/tree.c:1734 since
| |r8-4668-g8a5ee94a082b3d48
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, started with r8-4668-g8a5ee94a082b3d48.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
2020-04-26 19:34 ` [Bug tree-optimization/94775] " zhroma at gcc dot gnu.org
2020-04-27 4:33 ` [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48 marxin at gcc dot gnu.org
@ 2020-04-27 6:44 ` rguenth at gcc dot gnu.org
2020-04-27 17:19 ` msebor at gcc dot gnu.org
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-27 6:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (2 preceding siblings ...)
2020-04-27 6:44 ` rguenth at gcc dot gnu.org
@ 2020-04-27 17:19 ` msebor at gcc dot gnu.org
2020-04-27 17:24 ` msebor at gcc dot gnu.org
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-27 17:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The full stack trace shows the ICE occurs while formatting the text of a
warning. strip_typedefs is being called while formatting the type of an array
of d and when assertion below fires:
if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
|| TYPE_ALIGN (t) != TYPE_ALIGN (result))
{
gcc_assert (TYPE_USER_ALIGN (t));
if (remove_attributes)
during GIMPLE pass: vrp
in strip_typedefs, at cp/tree.c:1737
41 | m n::ad() const {
| ^
0xc6cab1 strip_typedefs(tree_node*, bool*, unsigned int)
/src/gcc/master/gcc/cp/tree.c:1737
0xa823d8 type_to_string
/src/gcc/master/gcc/cp/error.c:3214
0xa861d6 cp_printer
/src/gcc/master/gcc/cp/error.c:4289
0x268d13a pp_format(pretty_printer*, text_info*)
/src/gcc/master/gcc/pretty-print.c:1458
0x2666327 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
/src/gcc/master/gcc/diagnostic.c:1159
0x266694b diagnostic_impl
/src/gcc/master/gcc/diagnostic.c:1309
0x26671c7 warning_at(unsigned int, int, char const*, ...)
/src/gcc/master/gcc/diagnostic.c:1446
0x19b82ae vrp_prop::check_array_ref(unsigned int, tree_node*, bool)
/src/gcc/master/gcc/tree-vrp.c:3578
0x19ba715 check_array_bounds
/src/gcc/master/gcc/tree-vrp.c:4062
0x19f1508 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
/src/gcc/master/gcc/tree.c:12000
0x10ed4ac walk_gimple_op(gimple*, tree_node* (*)(tree_node**, int*, void*),
walk_stmt_info*)
/src/gcc/master/gcc/gimple-walk.c:202
0x19ba871 check_array_bounds_dom_walker::before_dom_children(basic_block_def*)
/src/gcc/master/gcc/tree-vrp.c:4120
0x23f5aed dom_walker::walk(basic_block_def*)
/src/gcc/master/gcc/domwalk.c:309
0x19ba8d5 vrp_prop::check_all_array_refs()
/src/gcc/master/gcc/tree-vrp.c:4137
0x19bdb47 vrp_prop::vrp_finalize(bool)
/src/gcc/master/gcc/tree-vrp.c:5209
0x19bdbdc execute_vrp
/src/gcc/master/gcc/tree-vrp.c:5277
0x19bdddb execute
/src/gcc/master/gcc/tree-vrp.c:5359
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (3 preceding siblings ...)
2020-04-27 17:19 ` msebor at gcc dot gnu.org
@ 2020-04-27 17:24 ` msebor at gcc dot gnu.org
2020-04-27 19:03 ` [Bug c++/94775] " msebor at gcc dot gnu.org
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-27 17:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The assertion was introduced in a fix for PR79900 by the commit below:
g:423aec8b5756 1734) if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
g:423aec8b5756 1735) || TYPE_ALIGN (t) != TYPE_ALIGN (result))
g:b71983a5baee 1736) {
g:423aec8b5756 1737) gcc_assert (TYPE_USER_ALIGN (t));
g:423aec8b5756 1738) if (remove_attributes)
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (4 preceding siblings ...)
2020-04-27 17:24 ` msebor at gcc dot gnu.org
@ 2020-04-27 19:03 ` msebor at gcc dot gnu.org
2020-04-29 17:30 ` mpolacek at gcc dot gnu.org
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-27 19:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Component|tree-optimization |c++
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
I don't think the warning code is doing anything wrong here. It seems like a
C++ front end problem. CC'ng Marek for his input.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (5 preceding siblings ...)
2020-04-27 19:03 ` [Bug c++/94775] " msebor at gcc dot gnu.org
@ 2020-04-29 17:30 ` mpolacek at gcc dot gnu.org
2020-04-29 17:31 ` mpolacek at gcc dot gnu.org
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-29 17:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The TYPE_USER_ALIGN (t) assert was there even before my change, but I agree
this is a latent problem not directly caused by r8-4668-g8a5ee94a082b3d48.
Here strip_typedefs gets "const d[0]" with TYPE_USER_ALIGN=0. But the result
built by
result = build_cplus_array_type (type, t0);
is "const char[0]" with TYPE_USER_ALIGN=1.
When we strip_typedefs the element of the array "const d", we see it's a
typedef_variant_p, so we look at its DECL_ORIGINAL_TYPE, which is char, but we
need to add the const qualifier, so we call
cp_build_qualified_type -> build_qualified_type
where get_qualified_type checks to see if we already have such a type by
walking the variants list, which in this case is:
char -> c -> const char -> const char -> d -> const d
Because check_base_type only checks TYPE_ALIGN and not TYPE_USER_ALIGN, we
choose the first const char, which has TYPE_USER_ALIGN set. If the element
type of an array has TYPE_USER_ALIGN, the array type gets it too. Thus the
discrepancy.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (6 preceding siblings ...)
2020-04-29 17:30 ` mpolacek at gcc dot gnu.org
@ 2020-04-29 17:31 ` mpolacek at gcc dot gnu.org
2020-04-29 17:40 ` jakub at gcc dot gnu.org
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-29 17:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So a fix could be this, but maybe it would make us create a lot more variants
(?):
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6493,7 +6493,8 @@ check_base_type (const_tree cand, const_tree base)
TYPE_ATTRIBUTES (base)))
return false;
/* Check alignment. */
- if (TYPE_ALIGN (cand) == TYPE_ALIGN (base))
+ if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
+ && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
return true;
/* Atomic types increase minimal alignment. We must to do so as well
or we get duplicated canonical types. See PR88686. */
@@ -6528,6 +6529,7 @@ check_aligned_type (const_tree cand, const_tree base,
unsigned int align)
&& TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
/* Check alignment. */
&& TYPE_ALIGN (cand) == align
+ && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base)
&& attribute_list_equal (TYPE_ATTRIBUTES (cand),
TYPE_ATTRIBUTES (base))
&& check_lang_type (cand, base));
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (7 preceding siblings ...)
2020-04-29 17:31 ` mpolacek at gcc dot gnu.org
@ 2020-04-29 17:40 ` jakub at gcc dot gnu.org
2020-04-29 17:51 ` mpolacek at gcc dot gnu.org
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-29 17:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #7)
> So a fix could be this, but maybe it would make us create a lot more
> variants (?):
>
> --- a/gcc/tree.c
> +++ b/gcc/tree.c
> @@ -6493,7 +6493,8 @@ check_base_type (const_tree cand, const_tree base)
> TYPE_ATTRIBUTES (base)))
> return false;
> /* Check alignment. */
> - if (TYPE_ALIGN (cand) == TYPE_ALIGN (base))
> + if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
> + && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
> return true;
> /* Atomic types increase minimal alignment. We must to do so as well
> or we get duplicated canonical types. See PR88686. */
> @@ -6528,6 +6529,7 @@ check_aligned_type (const_tree cand, const_tree base,
> unsigned int align)
> && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
> /* Check alignment. */
> && TYPE_ALIGN (cand) == align
> + && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base)
> && attribute_list_equal (TYPE_ATTRIBUTES (cand),
> TYPE_ATTRIBUTES (base))
> && check_lang_type (cand, base));
It looks like the right thing to me. I guess if we really wanted, we could
instrument the compiler to see how common this was (though best in a separate
build from just the above patch), i.e. when we would create a new type only
with this patch and not without.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (8 preceding siblings ...)
2020-04-29 17:40 ` jakub at gcc dot gnu.org
@ 2020-04-29 17:51 ` mpolacek at gcc dot gnu.org
2020-04-30 12:35 ` cvs-commit at gcc dot gnu.org
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-29 17:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
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
Status|NEW |ASSIGNED
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks, I'll try to obtain some more data. Mine for now.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (9 preceding siblings ...)
2020-04-29 17:51 ` mpolacek at gcc dot gnu.org
@ 2020-04-30 12:35 ` cvs-commit at gcc dot gnu.org
2020-04-30 12:48 ` [Bug c++/94775] [8/9 " mpolacek at gcc dot gnu.org
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-30 12:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:6318fe77395fc0dd59419bc4d69cd06ac0158e54
commit r10-8071-g6318fe77395fc0dd59419bc4d69cd06ac0158e54
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Apr 29 15:36:35 2020 -0400
tree: Don't reuse types if TYPE_USER_ALIGN differ [PR94775]
Here we trip on the TYPE_USER_ALIGN (t) assert in strip_typedefs: it
gets "const d[0]" with TYPE_USER_ALIGN=0 but the result built by
build_cplus_array_type is "const char[0]" with TYPE_USER_ALIGN=1.
When we strip_typedefs the element of the array "const d", we see it's
a typedef_variant_p, so we look at its DECL_ORIGINAL_TYPE, which is
char, but we need to add the const qualifier, so we call
cp_build_qualified_type -> build_qualified_type
where get_qualified_type checks to see if we already have such a type
by walking the variants list, which in this case is:
char -> c -> const char -> const char -> d -> const d
Because check_base_type only checks TYPE_ALIGN and not TYPE_USER_ALIGN,
we choose the first const char, which has TYPE_USER_ALIGN set. If the
element type of an array has TYPE_USER_ALIGN, the array type gets it too.
So we can make check_base_type stricter. I was afraid that it might make
us reuse types less often, but measuring showed that we build the same
amount of types with and without the patch, while bootstrapping.
PR c++/94775
* tree.c (check_base_type): Return true only if TYPE_USER_ALIGN
match.
(check_aligned_type): Check if TYPE_USER_ALIGN match.
* g++.dg/warn/Warray-bounds-10.C: New test.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (10 preceding siblings ...)
2020-04-30 12:35 ` cvs-commit at gcc dot gnu.org
@ 2020-04-30 12:48 ` mpolacek at gcc dot gnu.org
2020-05-04 14:36 ` cvs-commit at gcc dot gnu.org
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-30 12:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[8/9/10 Regression] ICE in |[8/9 Regression] ICE in
|strip_typedefs, at |strip_typedefs, at
|cp/tree.c:1734 since |cp/tree.c:1734 since
|r8-4668-g8a5ee94a082b3d48 |r8-4668-g8a5ee94a082b3d48
--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (11 preceding siblings ...)
2020-04-30 12:48 ` [Bug c++/94775] [8/9 " mpolacek at gcc dot gnu.org
@ 2020-05-04 14:36 ` cvs-commit at gcc dot gnu.org
2020-05-04 14:42 ` cvs-commit at gcc dot gnu.org
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-04 14:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:05be85b649173b10d0bf10255eb15275c2dcf509
commit r11-42-g05be85b649173b10d0bf10255eb15275c2dcf509
Author: Marek Polacek <polacek@redhat.com>
Date: Mon May 4 10:26:43 2020 -0400
Revert "tree: Don't reuse types if TYPE_USER_ALIGN differ [PR94775]"
This reverts commit 6318fe77395fc0dd59419bc4d69cd06ac0158e54.
Revert:
2020-04-30 Marek Polacek <polacek@redhat.com>
PR c++/94775
* tree.c (check_base_type): Return true only if TYPE_USER_ALIGN
match.
(check_aligned_type): Check if TYPE_USER_ALIGN match.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (12 preceding siblings ...)
2020-05-04 14:36 ` cvs-commit at gcc dot gnu.org
@ 2020-05-04 14:42 ` cvs-commit at gcc dot gnu.org
2020-05-04 14:43 ` [Bug c++/94775] [8/9/10/11 " mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-04 14:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:251c85372e088017e79894f50156901d112affee
commit r10-8088-g251c85372e088017e79894f50156901d112affee
Author: Marek Polacek <polacek@redhat.com>
Date: Mon May 4 10:41:24 2020 -0400
Revert "tree: Don't reuse types if TYPE_USER_ALIGN differ [PR94775]"
Revert:
2020-04-30 Marek Polacek <polacek@redhat.com>
PR c++/94775
* tree.c (check_base_type): Return true only if TYPE_USER_ALIGN
match.
(check_aligned_type): Check if TYPE_USER_ALIGN match.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (13 preceding siblings ...)
2020-05-04 14:42 ` cvs-commit at gcc dot gnu.org
@ 2020-05-04 14:43 ` mpolacek at gcc dot gnu.org
2020-05-11 18:50 ` zhroma at gcc dot gnu.org
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-04 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[8/9 Regression] ICE in |[8/9/10/11 Regression] ICE
|strip_typedefs, at |in strip_typedefs, at
|cp/tree.c:1734 since |cp/tree.c:1734 since
|r8-4668-g8a5ee94a082b3d48 |r8-4668-g8a5ee94a082b3d48
--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch reverted from 10/11.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (14 preceding siblings ...)
2020-05-04 14:43 ` [Bug c++/94775] [8/9/10/11 " mpolacek at gcc dot gnu.org
@ 2020-05-11 18:50 ` zhroma at gcc dot gnu.org
2020-05-11 18:53 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: zhroma at gcc dot gnu.org @ 2020-05-11 18:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #15 from Roman Zhuykov <zhroma at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #14)
> Patch reverted from 10/11.
Maybe I've missed something in gcc-patches, but why it was reverted? I can
imagine reasons to revert in 10 branch, but in master...
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (15 preceding siblings ...)
2020-05-11 18:50 ` zhroma at gcc dot gnu.org
@ 2020-05-11 18:53 ` mpolacek at gcc dot gnu.org
2021-01-28 15:51 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-11 18:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #16 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It caused testsuite failures on non-x86-64 platforms, see bug 94896.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (16 preceding siblings ...)
2020-05-11 18:53 ` mpolacek at gcc dot gnu.org
@ 2021-01-28 15:51 ` mpolacek at gcc dot gnu.org
2021-01-28 21:23 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-28 15:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #17 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Another attempt:
https://gcc.gnu.org/pipermail/gcc-patches/2021-January/564461.html
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (17 preceding siblings ...)
2021-01-28 15:51 ` mpolacek at gcc dot gnu.org
@ 2021-01-28 21:23 ` cvs-commit at gcc dot gnu.org
2021-01-28 21:26 ` [Bug c++/94775] [8/9/10 " mpolacek at gcc dot gnu.org
2021-04-09 20:03 ` mpolacek at gcc dot gnu.org
20 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-28 21:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
--- Comment #18 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:513ee7d2cd9a60339a50dc9c4cba39a8f1c707f0
commit r11-6963-g513ee7d2cd9a60339a50dc9c4cba39a8f1c707f0
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Jan 28 16:21:50 2021 -0500
tree: Don't reuse types if TYPE_USER_ALIGN differ [PR94775]
A year ago I submitted this patch:
~~
Here we trip on the TYPE_USER_ALIGN (t) assert in strip_typedefs: it
gets "const d[0]" with TYPE_USER_ALIGN=0 but the result built by
build_cplus_array_type is "const char[0]" with TYPE_USER_ALIGN=1.
When we strip_typedefs the element of the array "const d", we see it's
a typedef_variant_p, so we look at its DECL_ORIGINAL_TYPE, which is
char, but we need to add the const qualifier, so we call
cp_build_qualified_type -> build_qualified_type
where get_qualified_type checks to see if we already have such a type
by walking the variants list, which in this case is:
char -> c -> const char -> const char -> d -> const d
Because check_base_type only checks TYPE_ALIGN and not TYPE_USER_ALIGN,
we choose the first const char, which has TYPE_USER_ALIGN set. If the
element type of an array has TYPE_USER_ALIGN, the array type gets it too.
So we can make check_base_type stricter. I was afraid that it might make
us reuse types less often, but measuring showed that we build the same
amount of types with and without the patch, while bootstrapping.
~~
However, the patch broke a few tests on STRICT_ALIGNMENT platforms and
had to be reverted. This is another try. The original patch is kept
unchanged, but I added the finalize_type_size hunk that ought to fix the
STRICT_ALIGNMENT issues.
The problem is that finalize_type_size can clear TYPE_USER_ALIGN on the
main variant of a type, but doesn't clear it on any of the variants.
Then we end up with types which share the same TYPE_MAIN_VARIANT, but
their TYPE_CANONICAL differs and then the usual "canonical types differ
for identical types" follows.
I've created alignas19.C to exercise this scenario. What happens is:
- when parsing the class S we create a type S in xref_tag,
- we see alignas(8) so common_handle_aligned_attribute sets T_U_A in S,
- we parse the member function fn and build_memfn_type creates a copy
of S to add const; this variant has T_U_A set,
- we finish_struct S which calls layout_class_type -> finish_record_type
-> finalize_size_type where we reset T_U_A in S (but const S keeps it),
- finish_non_static_data_member for arr calls maybe_dummy_object with
type = S,
- maybe_dummy_object calls same_type_ignoring_top_level_qualifiers_p
to check if S and TREE_TYPE (current_class_ref), which is const S,
are the same,
- same_type_ignoring_top_level_qualifiers_p creates cv-unqualified
versions of the passed types. Previously we'd use our main variant
S when stripping "const S" of const, but since the T_U_A flags don't
match (check_base_type), we create a new variant S'. Then we crash in
comptypes because S and S' have the same TYPE_MAIN_VARIANT but
different TYPE_CANONICALs.
With my patch we'll clear T_U_A for S's variants too, and then instead
of S' we'll just use S.
gcc/ChangeLog:
PR c++/94775
* stor-layout.c (finalize_type_size): If we reset TYPE_USER_ALIGN
in
the main variant, maybe reset it in its variants too.
* tree.c (check_base_type): Return true only if TYPE_USER_ALIGN
match.
(check_aligned_type): Check if TYPE_USER_ALIGN match.
gcc/testsuite/ChangeLog:
PR c++/94775
* g++.dg/cpp0x/alignas19.C: New test.
* g++.dg/warn/Warray-bounds15.C: New test.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (18 preceding siblings ...)
2021-01-28 21:23 ` cvs-commit at gcc dot gnu.org
@ 2021-01-28 21:26 ` mpolacek at gcc dot gnu.org
2021-04-09 20:03 ` mpolacek at gcc dot gnu.org
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-28 21:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[8/9/10/11 Regression] ICE |[8/9/10 Regression] ICE in
|in strip_typedefs, at |strip_typedefs, at
|cp/tree.c:1734 since |cp/tree.c:1734 since
|r8-4668-g8a5ee94a082b3d48 |r8-4668-g8a5ee94a082b3d48
--- Comment #19 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk. Not sure if I want to backport to 10...
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
` (19 preceding siblings ...)
2021-01-28 21:26 ` [Bug c++/94775] [8/9/10 " mpolacek at gcc dot gnu.org
@ 2021-04-09 20:03 ` mpolacek at gcc dot gnu.org
20 siblings, 0 replies; 22+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-09 20:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94775
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #20 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think I won't backport as the fix caused bug 99510. Perhaps I could backport
both if someone really wants me to.
For now, fixed in GCC 11.
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2021-04-09 20:03 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 15:24 [Bug tree-optimization/94775] New: [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 zhroma at gcc dot gnu.org
2020-04-26 19:34 ` [Bug tree-optimization/94775] " zhroma at gcc dot gnu.org
2020-04-27 4:33 ` [Bug tree-optimization/94775] [8/9/10 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48 marxin at gcc dot gnu.org
2020-04-27 6:44 ` rguenth at gcc dot gnu.org
2020-04-27 17:19 ` msebor at gcc dot gnu.org
2020-04-27 17:24 ` msebor at gcc dot gnu.org
2020-04-27 19:03 ` [Bug c++/94775] " msebor at gcc dot gnu.org
2020-04-29 17:30 ` mpolacek at gcc dot gnu.org
2020-04-29 17:31 ` mpolacek at gcc dot gnu.org
2020-04-29 17:40 ` jakub at gcc dot gnu.org
2020-04-29 17:51 ` mpolacek at gcc dot gnu.org
2020-04-30 12:35 ` cvs-commit at gcc dot gnu.org
2020-04-30 12:48 ` [Bug c++/94775] [8/9 " mpolacek at gcc dot gnu.org
2020-05-04 14:36 ` cvs-commit at gcc dot gnu.org
2020-05-04 14:42 ` cvs-commit at gcc dot gnu.org
2020-05-04 14:43 ` [Bug c++/94775] [8/9/10/11 " mpolacek at gcc dot gnu.org
2020-05-11 18:50 ` zhroma at gcc dot gnu.org
2020-05-11 18:53 ` mpolacek at gcc dot gnu.org
2021-01-28 15:51 ` mpolacek at gcc dot gnu.org
2021-01-28 21:23 ` cvs-commit at gcc dot gnu.org
2021-01-28 21:26 ` [Bug c++/94775] [8/9/10 " mpolacek at gcc dot gnu.org
2021-04-09 20:03 ` 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).