From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2063) id C99BE38582BF; Fri, 9 Sep 2022 13:18:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C99BE38582BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662729509; bh=zKc5pA+4f9IgXlpn55uGT62IzI1OT1SNdE8+C1StxaQ=; h=From:To:Subject:Date:From; b=N0C//AQz20I5PAopYOLF+lHaPhXLkxr+gV8fRhR6WtHWTvnP6QG8p18Qv0ZyUGw3D rRIMakzlMtYyiUVFoectKwGE2mEOTyNtEfowuZ8Hk7S1eRO+MdftNBrm8hZFS4/rZe 5xXruQwQmzRWuIMMtvzrDN6OjoELWCaFHdlXt1V8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kewen Lin To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2562] Handle OPAQUE_TYPE specially in verify_type [PR106833] X-Act-Checkin: gcc X-Git-Author: Kewen Lin X-Git-Refname: refs/heads/master X-Git-Oldrev: eff73c104a3db882f3bc7f567f322e40470c7571 X-Git-Newrev: e230f11e9784eefed316df7dbc5df6ac999841b2 Message-Id: <20220909131829.C99BE38582BF@sourceware.org> Date: Fri, 9 Sep 2022 13:18:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e230f11e9784eefed316df7dbc5df6ac999841b2 commit r13-2562-ge230f11e9784eefed316df7dbc5df6ac999841b2 Author: Kewen Lin Date: Fri Sep 9 08:17:21 2022 -0500 Handle OPAQUE_TYPE specially in verify_type [PR106833] As PR106833 shows, cv-qualified opaque type can cause ICE during LTO. It exposes that we missd to handle OPAQUE_TYPE well in type verification. As Richi pointed out, also assuming that target will always define TYPE_MAIN_VARIANT TYPE_CANONICAL for opaque type, this patch is to check both are OPAQUE_TYPE_P and their modes are of MODE_OPAQUE class. Besides, it also checks the only available size and alignment information. PR middle-end/106833 gcc/ChangeLog: * tree.cc (verify_opaque_type): New function. (verify_type): Call verify_opaque_type for OPAQUE_TYPE. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr106833.c: New test. Diff: --- gcc/testsuite/gcc.target/powerpc/pr106833.c | 14 ++++++ gcc/tree.cc | 74 ++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.target/powerpc/pr106833.c b/gcc/testsuite/gcc.target/powerpc/pr106833.c new file mode 100644 index 00000000000..968d75184ff --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr106833.c @@ -0,0 +1,14 @@ +/* { dg-do link } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-require-effective-target lto } */ +/* { dg-options "-flto -mdejagnu-cpu=power10" } */ + +/* Verify there is no ICE in LTO mode. */ + +int main () +{ + float *b; + const __vector_quad c; + __builtin_mma_disassemble_acc (b, &c); + return 0; +} diff --git a/gcc/tree.cc b/gcc/tree.cc index 2f488e4467c..0546c8f4025 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -13680,6 +13680,71 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2, } } +/* For OPAQUE_TYPE T, it should have only size and alignment information + and its mode should be of class MODE_OPAQUE. This function verifies + these properties of T match TV which is the main variant of T and TC + which is the canonical of T. */ + +static void +verify_opaque_type (const_tree t, tree tv, tree tc) +{ + gcc_assert (OPAQUE_TYPE_P (t)); + gcc_assert (tv && tv == TYPE_MAIN_VARIANT (tv)); + gcc_assert (tc && tc == TYPE_CANONICAL (tc)); + + /* For an opaque type T1, check if some of its properties match + the corresponding ones of the other opaque type T2, emit some + error messages for those inconsistent ones. */ + auto check_properties_for_opaque_type = [](const_tree t1, tree t2, + const char *kind_msg) + { + if (!OPAQUE_TYPE_P (t2)) + { + error ("type %s is not an opaque type", kind_msg); + debug_tree (t2); + return; + } + if (!OPAQUE_MODE_P (TYPE_MODE (t2))) + { + error ("type %s is not with opaque mode", kind_msg); + debug_tree (t2); + return; + } + if (TYPE_MODE (t1) != TYPE_MODE (t2)) + { + error ("type %s differs by %", kind_msg); + debug_tree (t2); + return; + } + poly_uint64 t1_size = tree_to_poly_uint64 (TYPE_SIZE (t1)); + poly_uint64 t2_size = tree_to_poly_uint64 (TYPE_SIZE (t2)); + if (maybe_ne (t1_size, t2_size)) + { + error ("type %s differs by %", kind_msg); + debug_tree (t2); + return; + } + if (TYPE_ALIGN (t1) != TYPE_ALIGN (t2)) + { + error ("type %s differs by %", kind_msg); + debug_tree (t2); + return; + } + if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2)) + { + error ("type %s differs by %", kind_msg); + debug_tree (t2); + return; + } + }; + + if (t != tv) + check_properties_for_opaque_type (t, tv, "variant"); + + if (t != tc) + check_properties_for_opaque_type (t, tc, "canonical"); +} + /* Verify type T. */ void @@ -13687,6 +13752,14 @@ verify_type (const_tree t) { bool error_found = false; tree mv = TYPE_MAIN_VARIANT (t); + tree ct = TYPE_CANONICAL (t); + + if (OPAQUE_TYPE_P (t)) + { + verify_opaque_type (t, mv, ct); + return; + } + if (!mv) { error ("main variant is not defined"); @@ -13701,7 +13774,6 @@ verify_type (const_tree t) else if (t != mv && !verify_type_variant (t, mv)) error_found = true; - tree ct = TYPE_CANONICAL (t); if (!ct) ; else if (TYPE_CANONICAL (ct) != ct)