From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 7E6103884598 for ; Mon, 20 Nov 2023 09:56:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E6103884598 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7E6103884598 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700474201; cv=none; b=xsrTzg7d46tcTvO1v8ZVdy9oYjsYl9Sxd1nrdJprPkB1jznQbxrM9g1nQlRaHsLPkluGr35ryhpmdI9fni0DLeBHJN198W4D4zJIIdH0E0li52IpZHP+7nmce9ObdGaBMMR3riboLYssL/Fvwn09YWi2oYjGNIHE5S6XjVRzZhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700474201; c=relaxed/simple; bh=QSX4KRdtGbmDgrLy4hRW1i7p2QbMLFit4v/EUb1E0TY=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=Y1rPT1HbQVZgAenq2XZoSgUGC2iA0v2/G3C6Ec40g+xy1S1gXymkQK6+t42j9yHiSaK3/t/P1Exw/+o5yy/Md8AZbKMtkqLtRoi3dkFiAAPjFLEimCw1rW5AxHlzpBlYwx/41shDormDO+w27NvmGDtoazhHzoXJipaAS8I71xk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700474185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=K5chK6ydkV2R4MllnczmEfRfDM6oIbuJPWFLjKS6VFE=; b=g4ngi0K1DCfjKqYQURwXgMPeep8lWiv/pXn+ZLqbmLJoHm5Ao487/NiPOva/NTTu1fGgvV WDt58CtJt4sq8Ugaamo2v2jy6Bu/uNyw9PIoW6SSBL0yZaVbkwIUdnn8AQZmIxuOZZG8bm zCF57UHYQJt+mR22fgI8WDCMyvPCj5c= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-374-vKV_OhDlO4uO5jExzp5hvg-1; Mon, 20 Nov 2023 04:56:23 -0500 X-MC-Unique: vKV_OhDlO4uO5jExzp5hvg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 584F91C06E33 for ; Mon, 20 Nov 2023 09:56:23 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EBFA2026D4C for ; Mon, 20 Nov 2023 09:56:22 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH v3 07/11] c: Turn -Wimplicit-int into a permerror In-Reply-To: Message-ID: <39a598d6663a50d6df47aaeb01d097bcb62e11a7.1700473918.git.fweimer@redhat.com> References: X-From-Line: 39a598d6663a50d6df47aaeb01d097bcb62e11a7 Mon Sep 17 00:00:00 2001 Date: Mon, 20 Nov 2023 10:56:20 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-32.5 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: Most of these new permerrors are currently not diagnosed in system headers. gcc/ PR c/91093 PR c/96284 * doc/invoke.texi (Warning Options): Document changes. gcc/c/ * c-decl.cc (warn_defaults_to): Remove. (grok_declarator, start_function): Call permerror_opt instead of warn_defaults_to. (store_parm_decls_oldstyle): Call permerror_opt for OPT_Wimplicit_int. gcc/testsuite/ * gcc.dg/permerror-default.c (implicit_int_1, implicit_int_2) (implicit_int_3, implicit_int_4): Expect new permerror. * gcc.dg/permerror-system.c: Expect a single new permerror. * gcc.dg/Wimplicit-int-1.c: Compile with -fpermissive due to expected warning. * gcc.dg/Wimplicit-int-4.c: Likewise. * gcc.dg/Wimplicit-int-1a.c: New test. Copied from gcc.dg/Wimplicit-int-1.c, but expect errors. * gcc.dg/Wimplicit-int-4a.c: New test. Copied from gcc.dg/Wimplicit-int-4.c, but expect errors. * gcc.dg/gnu23-attr-syntax-2.c: Compile with -fpermissive due to expected implicit-int error. * gcc.dg/gnu23-attr-syntax-3.c: New test. Copied from gcc.dg/gnu23-attr-syntax-2.c, but expect an error. * gcc.dg/pr105635.c: Build with -fpermissive due to implicit int. * gcc.dg/pr105635-2.c: New test. Copied from gcc.dg/pr105635.c. Expect implicit int error. * gcc.dg/noncompile/pr79758.c: Build with -fpermissive due to implicit int. * gcc.dg/noncompile/pr79758-2.c: New test. Copied from gcc.dg/noncompile/pr79758.c. Expect implicit int error. --- gcc/c/c-decl.cc | 43 ++++++--------------- gcc/doc/invoke.texi | 7 +++- gcc/testsuite/gcc.dg/Wimplicit-int-1.c | 2 +- gcc/testsuite/gcc.dg/Wimplicit-int-1a.c | 11 ++++++ gcc/testsuite/gcc.dg/Wimplicit-int-4.c | 2 +- gcc/testsuite/gcc.dg/Wimplicit-int-4a.c | 11 ++++++ gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c | 2 +- gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c | 17 ++++++++ gcc/testsuite/gcc.dg/noncompile/pr79758-2.c | 6 +++ gcc/testsuite/gcc.dg/noncompile/pr79758.c | 1 + gcc/testsuite/gcc.dg/permerror-default.c | 12 +++--- gcc/testsuite/gcc.dg/permerror-system.c | 2 + gcc/testsuite/gcc.dg/pr105635-2.c | 11 ++++++ gcc/testsuite/gcc.dg/pr105635.c | 2 +- 14 files changed, 86 insertions(+), 43 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-1a.c create mode 100644 gcc/testsuite/gcc.dg/Wimplicit-int-4a.c create mode 100644 gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c create mode 100644 gcc/testsuite/gcc.dg/noncompile/pr79758-2.c create mode 100644 gcc/testsuite/gcc.dg/pr105635-2.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 011f0bf0a69..893e24f7dc6 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -647,8 +647,6 @@ static tree grokdeclarator (const struct c_declarator *, bool *, enum deprecated_states); static tree grokparms (struct c_arg_info *, bool); static void layout_array_type (tree); -static void warn_defaults_to (location_t, int, const char *, ...) - ATTRIBUTE_GCC_DIAG(3,4); static const char *header_for_builtin_fn (tree); /* T is a statement. Add it to the statement-tree. This is the @@ -6570,23 +6568,6 @@ warn_variable_length_array (tree name, tree size) } } -/* Print warning about defaulting to int if necessary. */ - -static void -warn_defaults_to (location_t location, int opt, const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - rich_location richloc (line_table, location); - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, - flag_isoc99 ? DK_PEDWARN : DK_WARNING); - diagnostic.option_index = opt; - diagnostic_report_diagnostic (global_dc, &diagnostic); - va_end (ap); -} - /* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS, considering only those c_declspec_words found in LIST, which must be terminated by cdw_number_of_elements. */ @@ -6875,12 +6856,12 @@ grokdeclarator (const struct c_declarator *declarator, else { if (name) - warn_defaults_to (loc, OPT_Wimplicit_int, - "type defaults to % in declaration " - "of %qE", name); + permerror_opt (loc, OPT_Wimplicit_int, + "type defaults to % in declaration " + "of %qE", name); else - warn_defaults_to (loc, OPT_Wimplicit_int, - "type defaults to % in type name"); + permerror_opt (loc, OPT_Wimplicit_int, + "type defaults to % in type name"); } } @@ -10290,10 +10271,10 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, } if (warn_about_return_type) - warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int - : (warn_return_type > 0 ? OPT_Wreturn_type - : OPT_Wimplicit_int), - "return type defaults to %"); + permerror_opt (loc, flag_isoc99 ? OPT_Wimplicit_int + : (warn_return_type > 0 ? OPT_Wreturn_type + : OPT_Wimplicit_int), + "return type defaults to %"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in pop_scope) with the BLOCK. */ @@ -10635,9 +10616,9 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) warn_if_shadowing (decl); if (flag_isoc99) - pedwarn (DECL_SOURCE_LOCATION (decl), - OPT_Wimplicit_int, "type of %qD defaults to %", - decl); + permerror_opt (DECL_SOURCE_LOCATION (decl), + OPT_Wimplicit_int, "type of %qD defaults to %", + decl); else warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_type, diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 055cca08f1c..eb7417fd9be 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6182,6 +6182,7 @@ that have their own flag: @gccoptlist{ -Wimplicit-function-declaration @r{(C)} +-Wimplicit-int @r{(C)} -Wint-conversion @r{(C)} -Wnarrowing @r{(C++)} } @@ -6853,8 +6854,10 @@ This warning is enabled by @option{-Wall} in C++. @opindex Wno-implicit-int @item -Wno-implicit-int @r{(C and Objective-C only)} This option controls warnings when a declaration does not specify a type. -This warning is enabled by default in C99 and later dialects of C, -and also by @option{-Wall}. +This warning is enabled by default, as an error, in C99 and later +dialects of C, and also by @option{-Wall}. The error can be downgraded +to a warning using @option{-fpermissive} (along with certain other +errors), or for this error alone, with @option{-Wno-error=implicit-int}. This warning is upgraded to an error by @option{-pedantic-errors}. diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c index 4a96e8f505d..fc7726c517e 100644 --- a/gcc/testsuite/gcc.dg/Wimplicit-int-1.c +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ static l; /* { dg-warning "type defaults to" } */ diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c new file mode 100644 index 00000000000..ef1835e2d3a --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-1a.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +static l; /* { dg-error "type defaults to" } */ + +foo (a) /* { dg-error "return type defaults to" } */ +/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */ +{ + auto p; /* { dg-error "type defaults to" } */ + typedef bar; /* { dg-error "type defaults to" } */ +} diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c index c9c6e8e5e95..99c61a76ecf 100644 --- a/gcc/testsuite/gcc.dg/Wimplicit-int-4.c +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wno-implicit -Wimplicit-int" } */ +/* { dg-options "-fpermissive -Wno-implicit -Wimplicit-int" } */ static l; /* { dg-warning "type defaults to" } */ diff --git a/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c new file mode 100644 index 00000000000..920a088f02b --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wimplicit-int-4a.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-implicit -Wimplicit-int" } */ + +static l; /* { dg-error "type defaults to" } */ + +foo (a) /* { dg-error "return type defaults to" } */ +/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } .-1 } */ +{ + auto p; /* { dg-error "type defaults to" } */ + typedef bar; /* { dg-error "type defaults to" } */ +} diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c index ba60f7a095a..8943534f2b2 100644 --- a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c +++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-2.c @@ -1,7 +1,7 @@ /* Test C23 attribute syntax. Invalid uses of attributes with GNU C features. */ /* { dg-do compile } */ -/* { dg-options "-std=gnu23 -w" } */ +/* { dg-options "-fpermissive -std=gnu23 -w" } */ /* Attributes cannot be used as prefix attributes on old-style parameter declarations or on function declarators with identifier diff --git a/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c new file mode 100644 index 00000000000..d73d6a3cfa8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gnu23-attr-syntax-3.c @@ -0,0 +1,17 @@ +/* Test C23 attribute syntax. Invalid uses of attributes with GNU C + features. Non-permissive variant. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu23 -w" } */ + +/* Attributes cannot be used as prefix attributes on old-style + parameter declarations or on function declarators with identifier + lists (removed from C23). */ + +void (*f(a, b) [[]])() int a, b; { } /* { dg-error "expected" } */ + +void f(x, y) int x; [[]] int y; { } /* { dg-error "expected" } */ +/* { dg-error "type of 'y' defaults to 'int'" "" { target *-*-* } .-1 } */ + +/* Nonempty attributes cannot be used as postfix attributes with + __auto_type. */ +__auto_type [[gnu::no_such_attr]] x = 1; /* { dg-error "'__auto_type' followed by" } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c new file mode 100644 index 00000000000..e6a27f952ef --- /dev/null +++ b/gcc/testsuite/gcc.dg/noncompile/pr79758-2.c @@ -0,0 +1,6 @@ +/* PR c/79758 */ +/* { dg-do compile } */ + +void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */ +void fn1 (b) { }; /* { dg-error "redefinition" } */ +/* { dg-error "defaults to 'int'" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/noncompile/pr79758.c b/gcc/testsuite/gcc.dg/noncompile/pr79758.c index a31216068f0..e42a44380fa 100644 --- a/gcc/testsuite/gcc.dg/noncompile/pr79758.c +++ b/gcc/testsuite/gcc.dg/noncompile/pr79758.c @@ -1,5 +1,6 @@ /* PR c/79758 */ /* { dg-do compile } */ +/* { dg-additional-options "-fpermissive" } */ void fn1 (int[a]) { }; /* { dg-error "undeclared here" } */ void fn1 (b) { }; /* { dg-error "redefinition" } */ diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c index f37f9189e41..90f2220037c 100644 --- a/gcc/testsuite/gcc.dg/permerror-default.c +++ b/gcc/testsuite/gcc.dg/permerror-default.c @@ -10,13 +10,13 @@ implicit_function_declaration (void) f1 (); /* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" } */ } -extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */ -typedef implicit_int_2; /* { dg-warning "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */ -extern implicit_int_3 (void); /* { dg-warning "'implicit_int_3' \\\[-Wimplicit-int\\]" } */ -implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */ -/* { dg-warning "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */ +extern implicit_int_1; /* { dg-error "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */ +typedef implicit_int_2; /* { dg-error "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */ +extern implicit_int_3 (void); /* { dg-error "'implicit_int_3' \\\[-Wimplicit-int\\]" } */ +implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */ +/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */ { - (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */ + (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */ } extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */ diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c index e4da4a99e9a..60c65ffc1d4 100644 --- a/gcc/testsuite/gcc.dg/permerror-system.c +++ b/gcc/testsuite/gcc.dg/permerror-system.c @@ -10,6 +10,8 @@ /* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" "" { target *-*-* } 10 } */ +/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} 16 } */ + /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 29 } */ /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 30 } */ /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */ diff --git a/gcc/testsuite/gcc.dg/pr105635-2.c b/gcc/testsuite/gcc.dg/pr105635-2.c new file mode 100644 index 00000000000..807eef0b7cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105635-2.c @@ -0,0 +1,11 @@ +/* PR c/105635 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */ + +foo (int x, int y) /* { dg-error "return type defaults to 'int'" } */ +{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */ + /* { dg-message "declared here" "" { target *-*-* } .-2 } */ + return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */ +} diff --git a/gcc/testsuite/gcc.dg/pr105635.c b/gcc/testsuite/gcc.dg/pr105635.c index aa02f593bfa..b98ea1b3c3b 100644 --- a/gcc/testsuite/gcc.dg/pr105635.c +++ b/gcc/testsuite/gcc.dg/pr105635.c @@ -1,6 +1,6 @@ /* PR c/105635 */ /* { dg-do compile } */ -/* { dg-options "-Wall" } */ +/* { dg-options "-fpermissive -Wall" } */ void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */ -- 2.42.0