From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7879) id 699363858C66; Wed, 15 Feb 2023 10:23:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 699363858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676456624; bh=0utvhfVeqWXpGC4Kb4u+DOkNSjh4UlYF+sYDDzp4l7I=; h=From:To:Subject:Date:From; b=unWwVlwIWw+6AOgLXtBoMYa3NBHeTLoGvG9gBf0RcaXgQhmk1ZfRqVIapCSaAl+Mc 0qeq0ag4nk+WmCQsaGzLoasCwBQVjH5E3XCcgGDJpt2dLr6/iBjeBCmKmrL6InwX6y 5XHx08DkKxipC4rU/ioel1xm2NOkch5Rh5NE21mM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Filip Kastl To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/pheeck/heads/sccp)] c: Propagate erroneous types to declaration specifiers [PR107805] X-Act-Checkin: gcc X-Git-Author: Florian Weimer X-Git-Refname: refs/users/pheeck/heads/sccp X-Git-Oldrev: b247a0490918f149caca9368814686a3412a2759 X-Git-Newrev: 7b78bbb13687b65172af27b2fe2dcbaaaf5136a1 Message-Id: <20230215102344.699363858C66@sourceware.org> Date: Wed, 15 Feb 2023 10:23:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7b78bbb13687b65172af27b2fe2dcbaaaf5136a1 commit 7b78bbb13687b65172af27b2fe2dcbaaaf5136a1 Author: Florian Weimer Date: Thu Nov 24 11:00:54 2022 +0100 c: Propagate erroneous types to declaration specifiers [PR107805] 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-2.c: Likewise. Diff: --- 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" } */