From patchwork Fri May 19 20:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 96622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1506859vqo; Fri, 19 May 2023 13:39:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mid5c8XnNWzI0HxhO2OXRCxBImXPBG5Mb+4HX3JHexhNMAZx9HJv9HDwwBroyCvP4de47 X-Received: by 2002:a17:907:749:b0:966:3310:50ae with SMTP id xc9-20020a170907074900b00966331050aemr2477835ejb.47.1684528741513; Fri, 19 May 2023 13:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684528741; cv=none; d=google.com; s=arc-20160816; b=o4aKY3jFtZqWtH4haJFggaLzj1vYn+V2er6aCPt/UxpziLNi9UJuUO2dZgAvcZx+fO +k6t6NDZ0SGitthDguEdOGzvgwNriZaWSMwdFFD4oLquhMCHnEPxiOAoe79IruSH89nQ HIIfxOW308bUfm7XiTwTBjUqxZlF/MmsZi31I90mboIhTegBvthHAxRKxVV5aUojhN3u Zaf9yIxvy2WZceI8h0Js4duWngT8UfWpQB1soDmZzMGCoQuHXLOztdcenFPqEkxyDpGL Das78mj+0TsTcVgvLJZv32l2+dhd2kHoHbAnWu256QpyJk/F0NY8FRiLkTDMoUCLZSgG wdmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:user-agent:date:cc:to :subject:message-id:dkim-filter:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=kj6Cozh+jRM4XrXQR30DQ7aTI22dIxfrGgj/k7g+KuI=; b=Hc2oen+pugH4RlUfnxHo7XyDU6FycQi2PGfQpHn5NsXXikf2Gcb1VP67k6IMsxejie StuFonqbP63WDjz+vV1Lu2LIUqi9+TcFw8yNiJ81hq8msmFKIr7G8IyYMfnqanx1osyP wF+C++GZZQ++Mccypck/troEf3e4yaJ0xSJ1BaU4JmC1iV/D8JqL5mU+cfLMdxjVCyCC 6ZyhnmPQmH9VgLvN16NJsvsOUB6RKCAHxRE/jh6doytt1wAUHYQk0WLRgW8rnnjaKmkn KabjwoBcdSvwXfzL19JL8GtU0uqujNXNpIIfi1WWPiTJ7RzaUepC8/PbmPeU8axWqPBW ju4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Qm6yb34h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ew7-20020a170907950700b0096a90bba2ddsi59019ejc.29.2023.05.19.13.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 13:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Qm6yb34h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F7A13858C2D for ; Fri, 19 May 2023 20:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F7A13858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684528740; bh=kj6Cozh+jRM4XrXQR30DQ7aTI22dIxfrGgj/k7g+KuI=; h=Subject:To:Cc:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Qm6yb34hgF2rPltB4qkGLJkyswKlIy2ba8rtkEgQo34d/7HLF/AltMbs+EH2/our2 /c9pDnUTTyOizEySXhU8pwtnidI55P5/F9QTPjOrSuyFGEUb/sHGkdMvssUrGj7f28 1nEDeTgjJzyhFvY9L7ABogtGRksNdxqXGyekh7Eg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id B26993858C41 for ; Fri, 19 May 2023 20:38:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B26993858C41 Received: from vra-174-189.tugraz.at (vra-174-189.tugraz.at [129.27.174.189]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4QNJZT5MkTz1LLyW; Fri, 19 May 2023 22:38:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4QNJZT5MkTz1LLyW Message-ID: Subject: [C PATCH] Remove dead code related to type compatibility across TUs. To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Fri, 19 May 2023 22:38:09 +0200 User-Agent: Evolution 3.38.3-1+deb11u1 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.116 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Uecker via Gcc-patches From: Martin Uecker Reply-To: Martin Uecker Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766356409638889331?= X-GMAIL-MSGID: =?utf-8?q?1766356409638889331?= Repost for stage 1. C: Remove dead code related to type compatibility across TUs. Code to detect struct/unions across the same TU is not needed anymore. Code for determining compatibility of tagged types is preserved as it will be used for C2X. Some errors in the unused code are fixed. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-decl.cc (set_type_context): Remove. (pop_scope, diagnose_mismatched_decls, pushdecl): Remove dead code. * c-typeck.cc (comptypes_internal): Remove dead code. (same_translation_unit_p): Remove. (tagged_types_tu_compatible_p): Some fixes. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index f63c1108ab5..70345b4b019 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -1155,16 +1155,6 @@ update_label_decls (struct c_scope *scope) } } -/* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */ - -static void -set_type_context (tree type, tree context) -{ - for (type = TYPE_MAIN_VARIANT (type); type; - type = TYPE_NEXT_VARIANT (type)) - TYPE_CONTEXT (type) = context; -} - /* Exit a scope. Restore the state of the identifier-decl mappings that were in effect when this scope was entered. Return a BLOCK node containing all the DECLs in this scope that are of interest @@ -1253,7 +1243,6 @@ pop_scope (void) case ENUMERAL_TYPE: case UNION_TYPE: case RECORD_TYPE: - set_type_context (p, context); /* Types may not have tag-names, in which case the type appears in the bindings list with b->id NULL. */ @@ -1364,12 +1353,7 @@ pop_scope (void) the TRANSLATION_UNIT_DECL. This makes same_translation_unit_p work. */ if (scope == file_scope) - { DECL_CONTEXT (p) = context; - if (TREE_CODE (p) == TYPE_DECL - && TREE_TYPE (p) != error_mark_node) - set_type_context (TREE_TYPE (p), context); - } gcc_fallthrough (); /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have @@ -2318,21 +2302,18 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, { if (DECL_INITIAL (olddecl)) { - /* If both decls are in the same TU and the new declaration - isn't overriding an extern inline reject the new decl. - In c99, no overriding is allowed in the same translation - unit. */ - if ((!DECL_EXTERN_INLINE (olddecl) - || DECL_EXTERN_INLINE (newdecl) - || (!flag_gnu89_inline - && (!DECL_DECLARED_INLINE_P (olddecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (olddecl))) - && (!DECL_DECLARED_INLINE_P (newdecl) - || !lookup_attribute ("gnu_inline", - DECL_ATTRIBUTES (newdecl)))) - ) - && same_translation_unit_p (newdecl, olddecl)) + /* If the new declaration isn't overriding an extern inline + reject the new decl. In c99, no overriding is allowed + in the same translation unit. */ + if (!DECL_EXTERN_INLINE (olddecl) + || DECL_EXTERN_INLINE (newdecl) + || (!flag_gnu89_inline + && (!DECL_DECLARED_INLINE_P (olddecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (olddecl))) + && (!DECL_DECLARED_INLINE_P (newdecl) + || !lookup_attribute ("gnu_inline", + DECL_ATTRIBUTES (newdecl))))) { auto_diagnostic_group d; error ("redefinition of %q+D", newdecl); @@ -3360,18 +3341,11 @@ pushdecl (tree x) type to the composite of all the types of that declaration. After the consistency checks, it will be reset to the composite of the visible types only. */ - if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && b->u.type) + if (b && b->u.type) TREE_TYPE (b->decl) = b->u.type; - /* The point of the same_translation_unit_p check here is, - we want to detect a duplicate decl for a construct like - foo() { extern bar(); } ... static bar(); but not if - they are in different translation units. In any case, - the static does not go in the externals scope. */ - if (b - && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) - && duplicate_decls (x, b->decl)) + /* the static does not go in the externals scope. */ + if (b && duplicate_decls (x, b->decl)) { tree thistype; if (vistype) diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index f619e2a67e7..9a5d6e003ca 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1259,7 +1259,7 @@ comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p, case ENUMERAL_TYPE: case RECORD_TYPE: case UNION_TYPE: - if (val != 1 && !same_translation_unit_p (t1, t2)) + if (val != 1 && false) { tree a1 = TYPE_ATTRIBUTES (t1); tree a2 = TYPE_ATTRIBUTES (t2); @@ -1268,11 +1268,11 @@ comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p, && ! attribute_list_contained (a2, a1)) break; - if (attrval != 2) - return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p, - different_types_p); val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p, different_types_p); + + if (attrval != 2) + return val; } break; @@ -1347,40 +1347,7 @@ comp_target_types (location_t location, tree ttl, tree ttr) /* Subroutines of `comptypes'. */ -/* Determine whether two trees derive from the same translation unit. - If the CONTEXT chain ends in a null, that tree's context is still - being parsed, so if two trees have context chains ending in null, - they're in the same translation unit. */ - -bool -same_translation_unit_p (const_tree t1, const_tree t2) -{ - while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL) - switch (TREE_CODE_CLASS (TREE_CODE (t1))) - { - case tcc_declaration: - t1 = DECL_CONTEXT (t1); break; - case tcc_type: - t1 = TYPE_CONTEXT (t1); break; - case tcc_exceptional: - t1 = BLOCK_SUPERCONTEXT (t1); break; /* assume block */ - default: gcc_unreachable (); - } - while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL) - switch (TREE_CODE_CLASS (TREE_CODE (t2))) - { - case tcc_declaration: - t2 = DECL_CONTEXT (t2); break; - case tcc_type: - t2 = TYPE_CONTEXT (t2); break; - case tcc_exceptional: - t2 = BLOCK_SUPERCONTEXT (t2); break; /* assume block */ - default: gcc_unreachable (); - } - - return t1 == t2; -} /* Allocate the seen two types, assuming that they are compatible. */ @@ -1531,6 +1498,7 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, case UNION_TYPE: { struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); + if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2))) { tu->val = 0; @@ -1609,7 +1577,7 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, return 0; } } - tu->val = needs_warning ? 2 : 10; + tu->val = needs_warning ? 2 : 1; return tu->val; } @@ -1617,6 +1585,12 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree t2, { struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); + if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2))) + { + tu->val = 0; + return 0; + } + for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2; s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))