From patchwork Tue Nov 22 12:21:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 24335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2167044wrr; Tue, 22 Nov 2022 04:21:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7G36iH/PHVMbg1P0VJCQgkzfzFSWkzHt4DDn6VsYjRPl346eNOAbXfvQMCbjqKQ5j1QgYl X-Received: by 2002:aa7:c94f:0:b0:460:9994:1b9b with SMTP id h15-20020aa7c94f000000b0046099941b9bmr7112113edt.155.1669119714375; Tue, 22 Nov 2022 04:21:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669119714; cv=none; d=google.com; s=arc-20160816; b=r6PI3aqrf3RGq7UfDCEt2jMgnwPHnuMY86MR+dB3H2dogqB/AjOwjvCjqCeUqzyCNx 6xsK5vdYkm1rCLToMhvQDTCADJ5D8JAzWiWL1mVOloQZ4AOO8JHy98yfNIXvB/17hPZS h4AeSYnr83BUlWp3y3/FBTs0RLqJ7dXmMCHoXw/AjdZ8qDI7qTT34tMbwDOU5EcThW+7 QE6CUwRwDv9/2T8Qv+7LujzNMUEAsRIBCL0iVl0S5hjCXOEaytubLJcSlLg1+10BuYMm p9OvijH2aZKRToNy+nbmYnhEndWOo+LO212TUClKOZ2sLAJCm81Tm9wCKKEJdQaiddCa Ndgw== 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:mime-version :user-agent:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=8r5RHu1SnM1hfWvLDcpEet36M2l9buH8sAByEZ1O+4Y=; b=a2W69SUHDfqDEdPJC1UIXNDnufgQEiZ2dPYbcQlRpR1yP6pskjiK8rtXu2e2I4sy/v IJJlMrE+BRt1KqIeb0hV7l/Bha9/hsgn/W7I9K9ylxSlH9mjrjCtvg20JNVFtoS54L6N sCuv5NW8RgQ8vh/wIlhHKltYQtVIKLCz+4gFgBaCvxh+c5LhAgRAWuDWgnWH+tBajdlV Rm6qPtvyQ5Vjr9vNSLR0jWnWu+FqJldx3CvWUCu1JZR/epo3naAizM3MZwfof6gCXQv4 mYimEisq+RjWdNsI3kRmG0DnYzU6/YrepdtDmh5TY9UuOYn5viAAd/WfstEgIjlCFCn1 Xomg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hn9hpgSk; 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 f11-20020a056402354b00b00461bbc0f929si12721025edd.184.2022.11.22.04.21.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 04:21:54 -0800 (PST) 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=Hn9hpgSk; 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 DE9E138582A4 for ; Tue, 22 Nov 2022 12:21:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE9E138582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669119711; bh=8r5RHu1SnM1hfWvLDcpEet36M2l9buH8sAByEZ1O+4Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Hn9hpgSkFppO/3LVvYN+oA3kFad2SNMsoBjsxs+f7vfspooPpdrGFiiCoIg1r9XGT 3F5mGXZrKe8fstQ0Q0Z4XsZKwsLejbliNXbCh6klsPLVdf0IlpmfXZklGZ2lTPanpq mA/eszFyUdIIHty3T/eXkze3XF47k2w9uFqGmGe8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9FCDD3858D20 for ; Tue, 22 Nov 2022 12:21:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FCDD3858D20 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-540--vV3iLDJMfGj_e7YCBjW7g-1; Tue, 22 Nov 2022 07:21:06 -0500 X-MC-Unique: -vV3iLDJMfGj_e7YCBjW7g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC76785A59D for ; Tue, 22 Nov 2022 12:21:05 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BC1140C835A for ; Tue, 22 Nov 2022 12:21:05 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Propagate erroneous types to declaration specifiers [PR107805] Date: Tue, 22 Nov 2022 13:21:01 +0100 Message-ID: <87cz9fqixe.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Florian Weimer via Gcc-patches From: Florian Weimer Reply-To: Florian Weimer 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?1750198873724368549?= X-GMAIL-MSGID: =?utf-8?q?1750198873724368549?= Without this change, finish_declspecs cannot tell that whether there was an erroneous type specified, or no type at all. This may result in additional diagnostics for implicit ints, or missing diagnostics for multiple types. PR c/107805 gcc/c/ * c-decl.cc (declspecs_add_type): Propagate error_mark_bode from type to specs. gcc/testsuite/ * gcc.dg/pr107805-1.c: New test. * gcc.dg/pr107805-1.c: Likewise. --- Note regarding testing: I boostrap with c,c++,lto on x86-64 (non-multlib) and diffed these .sum files: gcc/testsuite/gcc/gcc.sum gcc/testsuite/g++/g++.sum x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum Apart from timestamps, the only differences I get is this change: base-commit: e4faee8d02ec5d65bf418612f7181823eb08c078 --- ./gcc/testsuite/gcc/gcc.sum 2022-11-22 05:45:33.813264761 -0500 +++ /tmp/b/build/./gcc/testsuite/gcc/gcc.sum 2022-11-22 06:39:10.667590185 -0500 @@ -83303,6 +83303,11 @@ PASS: gcc.dg/pr107618.c (test for bogus messages, line 9) PASS: gcc.dg/pr107618.c (test for excess errors) PASS: gcc.dg/pr107686.c (test for excess errors) +PASS: gcc.dg/pr107805-1.c (test for errors, line 3) +PASS: gcc.dg/pr107805-1.c (test for excess errors) +PASS: gcc.dg/pr107805-2.c (test for errors, line 3) +PASS: gcc.dg/pr107805-2.c (test for errors, line 4) +PASS: gcc.dg/pr107805-2.c (test for excess errors) PASS: gcc.dg/pr11459-1.c (test for excess errors) PASS: gcc.dg/pr11492.c (test for bogus messages, line 8) PASS: gcc.dg/pr11492.c (test for excess errors) @@ -190486,7 +190491,7 @@ === gcc Summary === -# of expected passes 185932 +# of expected passes 185937 # of unexpected failures 99 # of unexpected successes 20 # of expected failures 1484 So I think this means there are no test suite regressions. Thanks, Florian gcc/c/c-decl.cc | 6 ++---- gcc/testsuite/gcc.dg/pr107805-1.c | 5 +++++ gcc/testsuite/gcc.dg/pr107805-2.c | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 098e475f65d..4adb89e4aaf 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -12243,11 +12243,9 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs, error_at (loc, "two or more data types in declaration specifiers"); else if (TREE_CODE (type) == TYPE_DECL) { - if (TREE_TYPE (type) == error_mark_node) - ; /* Allow the type to default to int to avoid cascading errors. */ - else + specs->type = TREE_TYPE (type); + if (TREE_TYPE (type) != error_mark_node) { - specs->type = TREE_TYPE (type); specs->decl_attr = DECL_ATTRIBUTES (type); specs->typedef_p = true; specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); diff --git a/gcc/testsuite/gcc.dg/pr107805-1.c b/gcc/testsuite/gcc.dg/pr107805-1.c new file mode 100644 index 00000000000..559b6a5586e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107805-1.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +typedef int t; +typedef struct { double a; int b; } t; /* { dg-error "conflicting types" } */ +t x; /* No warning here. */ + diff --git a/gcc/testsuite/gcc.dg/pr107805-2.c b/gcc/testsuite/gcc.dg/pr107805-2.c new file mode 100644 index 00000000000..fa5fa4ce273 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107805-2.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +typedef int t; +typedef struct { double a; int b; } t; /* { dg-error "conflicting types" } */ +t char x; /* { dg-error "two or more data types" } */