From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 3FA963858D20 for ; Thu, 14 Dec 2023 21:10:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FA963858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3FA963858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.129.153 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702588225; cv=none; b=Yym0CTMxZ2SHyhZ5McQ9pw5gQAlqrSVuIBM4g+py+WTkDvh27Jl6ppN7f3Z546jhjCZyzzBh/BTumJiWMz9AmVWS5Oi+8Wz/+5TVf0otBNnh+aP1fgPdGJXAWdJJ2Q8KJ0R+jDlnZszvgStuq5vH/p1Ex2ZEp6ySf7fbHwVWE+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702588225; c=relaxed/simple; bh=vW8npU7CXObl6ZMb3v55PMuO+waTQptQT9sse18OXrY=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=s1pQPbcm7AXtLw//iCWHhcKn+5ydXzubb8+p57oCkqA4VOZi1c6J4IG/9EpqgPOJdC3i6DQrjPzQxhdioUls0zO/aOXZ9SQna8cXpefyZi/yAlfQCX2CbhJKc8o8m/YZ6ORmm9+NxCHRhCGj8tbWqWFl5ZrV/4LdkIVG9lsuPtI= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: NcNKXl4gT0C7wKpn6Kqz0w== X-CSE-MsgGUID: U35DLcZgShy9Jgz4O8ZWuA== X-IronPort-AV: E=Sophos;i="6.04,276,1695715200"; d="scan'208";a="28607958" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 14 Dec 2023 13:10:23 -0800 IronPort-SDR: MBxlJmOS45S1IjHXpxJvMkhvGYQzfx5vMXcmwEr/M9/jEYPfPjMxsuv6BrvHgie/2vPz2d2bme dFbhfhtG4ftLMMK7fw1Ezy4Y7rO7lbXSdLma2o6NqD/s2m4Mb2DB5ptgoCGW1I9pWadMTFZ4ey 99RTAeKUw2nQCgZAMnP/twLvbqaociJ1fvSA0DVFdlXrfX7ajnPK8nIbwK6SN0a5LQovkfSPPu 5ERXAnmZ/gwVghhV189iqqLzeKeGRwH3Pkx4dtaxswe/Wjy1pdzEHwHpKRcDcDe3FORrXrjtWV TAo= Date: Thu, 14 Dec 2023 21:10:19 +0000 From: Joseph Myers To: Martin Uecker CC: Subject: Re: [V4] [PATCH 3/4] c23: aliasing of compatible tagged types In-Reply-To: <7a7036f0ac5d5bb1644f723ff0b30b81f8fca1c6.camel@tugraz.at> Message-ID: References: <02a9b94e4d653b6f1b9f89a1b62187f46e871738.camel@tugraz.at> <7a7036f0ac5d5bb1644f723ff0b30b81f8fca1c6.camel@tugraz.at> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3108.7 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 27 Nov 2023, Martin Uecker wrote: > diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h > index a5dd9a37944..ece5b6a5d26 100644 > --- a/gcc/c/c-tree.h > +++ b/gcc/c/c-tree.h > @@ -758,6 +758,7 @@ extern tree require_complete_type (location_t, tree); > extern bool same_translation_unit_p (const_tree, const_tree); > extern int comptypes (tree, tree); > extern bool comptypes_same_p (tree, tree); > +extern int comptypes_equiv_p (tree, tree); This function should return bool. > @@ -1250,6 +1266,9 @@ comptypes_internal (const_tree type1, const_tree type2, > > if ((d1 == NULL_TREE) != (d2 == NULL_TREE)) > data->different_types_p = true; > + /* Ignore size mismatches. */ > + if (data->equiv) > + return 1; > /* Sizes must match unless one is missing or variable. */ > if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2) > return true; > @@ -1467,6 +1486,9 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, > if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2))) > return false; > > + if (data->equiv && (C_TYPE_VARIABLE_SIZE (t1) || C_TYPE_VARIABLE_SIZE (t2))) > + return 0; > + > for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); > s1 && s2; > s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2)) > @@ -1486,6 +1508,15 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, > && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), > DECL_FIELD_BIT_OFFSET (s2)) != 1) > return false; > + > + tree st1 = TYPE_SIZE (TREE_TYPE (s1)); > + tree st2 = TYPE_SIZE (TREE_TYPE (s2)); > + > + if (data->equiv > + && st1 && TREE_CODE (st1) == INTEGER_CST > + && st2 && TREE_CODE (st2) == INTEGER_CST > + && !tree_int_cst_equal (st1, st2)) > + return 0; And these functions do return bool, so you should use true and false instead of 1 and 0. > +/* The structs are incompatible so can be assumed not to > + * alias, but this is not exploited. So do not check for > + * this below but check the warning about incompatibility. */ > + > +int test_bar3(struct bar* a, void* b) > +{ > + a->x = 1; > + > + struct bar { int x; int f[1]; }* p = b; > + struct bar* q = a; /* { dg-warning "incompatible" } */ I expect you'll now need -fpermissive or -Wno-error=incompatible-pointer-types (this is an execution test so you need to stop this being an error, but see below). > + // allow both results here > + int r = test_bar3(&z, &z); > + if ((r != 2) && (r != 1)) > + __builtin_abort(); I don't think you should really be executing this call at all (aliasing not allowed means undefined behavior at runtime); better to put this in a separate compile-only test (which would also avoid the need for -fpermissive or -Wno-error=incompatible-pointer-types because once it's no longer an execution test, having an error is OK). -- Joseph S. Myers joseph@codesourcery.com