public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/94775] [8/9/10/11 Regression] ICE in strip_typedefs, at cp/tree.c:1734 since r8-4668-g8a5ee94a082b3d48 Date: Thu, 28 Jan 2021 21:23:53 +0000 [thread overview] Message-ID: <bug-94775-4-NoNaLduGFj@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-94775-4@http.gcc.gnu.org/bugzilla/> 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.
next prev parent reply other threads:[~2021-01-28 21:23 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 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 [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94775-4-NoNaLduGFj@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).