From patchwork Tue Nov 14 17:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 165034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2094516rwb; Tue, 14 Nov 2023 09:51:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyD+6X+uYRptg1I/UkcL/jI2QtGoRw3GgLh/oguDvOQmwqKqC9W0knTBofOFf1hkQtV2d1 X-Received: by 2002:a05:6358:e49f:b0:16b:c8cd:42d4 with SMTP id by31-20020a056358e49f00b0016bc8cd42d4mr3708919rwb.22.1699984276184; Tue, 14 Nov 2023 09:51:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699984276; cv=pass; d=google.com; s=arc-20160816; b=pfV9RbtwiUq+YqG1c3ELdYzqZosbpUshiYMcWtBoZLzYwq16VynqSIlnWW3MJTd603 BzXvAMZRN2xiYyixCigs9+DGXOqCTHMXW1QQ02nVOnSkZEBjVwbAoPpWxx7OF6daoRNs gXiS7LO8ZxEdqhPAdsOBXegiY27oPvc/Xjf8uKytqRymGgE2b3+uE++5/EshbWwPRaP7 uAFKUh7ketDZa5Km57/foaib0CdOf7iYxFB2eexAp5tlz5Pz7hRf5PsenDcPMdtxxb8N fvcB2GMkYYwlkoZeBsl4jM4E/KdGVKARjoMPEyJ1zSQf00BZDkNd5kPauiRoMerxfFts z6Dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent:date :references:message-id:in-reply-to:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=96eHcX4l4fk7edHFSATBNBqyVewm8xby7y5BylmHgnc=; fh=brrc/l6yGUGxGhv8SjiSoDgfQmQ4atC/Em9G49NRuIw=; b=e7UxDFxft06iZtAB4P8fF19XA44tde1MZek8UGBoIIhlpx2SR3l/HaIOSXD4oBXXK2 7PkpwpevbsEkwk+qYp+cwmahK93uHgSLNGqLKdrUODZyooiNY9xraatWb2wmSOZZ8D/7 KOZhYMMMyKqCmRgQ8jsNuLnnApBYafwWCvounxevuXZlt3RdM4Pi+jqT5DBeQwteHu8l QIG9y4BA1b36483QeizX4DwJH5/+RWrpJ+zbQpu++howqCvhQTtRKNx8lE4XfmuQL3gK 0Sat1iuMdD1+BZ+CyDQsVpNnpVar5bKdMlZkT1usxSCGosr713lAiNVkklo87ebDrGQB 9rRQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cMiR0dgA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a16-20020a0ccdd0000000b006779f704f86si7040624qvn.85.2023.11.14.09.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 09:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cMiR0dgA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B4B3385828F for ; Tue, 14 Nov 2023 17:51:11 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 44AC53858C54 for ; Tue, 14 Nov 2023 17:50:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44AC53858C54 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 44AC53858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699984242; cv=none; b=gB7swL5SBAzrZJlekYaDz6qfWUhCAItGbUBo8PCN/mg2Xbp81RAhoI9al2n+9jX6VIe7RMpZmNGaEmBlU9CvkrqlkLuB5EktswdG7diAsvTuOt6U397ITMqBdWwJa16xdmYx02eZ4He1LkFwc41WISLPZjmMRlROz0Af592vAoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699984242; c=relaxed/simple; bh=xzLXoL6vqYoqTHVTzJCtOEtNUS3g69ltj4NXWYUd5Jc=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=LVQ7vVXaxAbu/sXLzWgCf4XKgdBKxr6Hhxj6cGEGYEUUhZ1ZKMmKXTHsJxfi00BfaOnkDcZcMkjct+ei/M+nR9QRMBBegydd3cfyRMs2+8PwWeIH34a4++M1zK+UzGr7AxxEkjthMqOsCdC4EBt2JIHZD/BKUhRWaOye9QhVZig= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699984234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=96eHcX4l4fk7edHFSATBNBqyVewm8xby7y5BylmHgnc=; b=cMiR0dgAnYIRsGnh56ddPp8FQraLJLU3QwmBQPaxBj2921uVv0AHzOo3s+PWOzumcfqiMo P1uegXN/svBs4pQKVxG9XxX7XjwH9w9/CEZ/ON+56Ag62drMvGeVvwlsK/At1u0caz2SE2 /PrCtCLA+4DARgaQWZ67RcOJ6F8Mqzo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-nkdmN-lANqCkcpRzyh2QnQ-1; Tue, 14 Nov 2023 12:50:31 -0500 X-MC-Unique: nkdmN-lANqCkcpRzyh2QnQ-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 0964A811E82; Tue, 14 Nov 2023 17:50:31 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAA182026D4C; Tue, 14 Nov 2023 17:50:28 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, jeffreyalaw@gmail.com, joseph@codesourcery.com, sam@gentoo.org Subject: [PATCH v2 2/8] c: Turn int-conversion warnings into permerrors In-Reply-To: Message-ID: <64b3080a229e541cd6f1a687cbe0690bc0d1c2c5.1699983736.git.fweimer@redhat.com> References: X-From-Line: 64b3080a229e541cd6f1a687cbe0690bc0d1c2c5 Mon Sep 17 00:00:00 2001 Date: Tue, 14 Nov 2023 18:50:26 +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 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782562712434251484 X-GMAIL-MSGID: 1782562712434251484 gcc/ * doc/invoke.texi (Warning Options): Document changes. gcc/c/ PR c/96284 PR c/106416 * c-typeck.cc (build_conditional_expr): Use permerror_opt for pointer/integer type mismatches, based on -Wint-conversion. (pedwarn_permerror_init, permerror_init): New function. (pedwarn_init): Call pedwarn_permerror_init. (convert_for_assignment): Use permerror_opt and permerror_init for -Wint-conversion warnings. gcc/testsuite/ * gcc.dg/permerror-default.c (int_conversion_1) (int_conversion_2): Expect the new permerrors. * gcc.dg/permerror-system.c: Likewise. * c-c++-common/pr77624-1.c (foo, bar): Expect error instead of warning. * gcc.dg/Wint-conversion-2.c: Compile with -fpermissive due to expected int-conversion warning. * gcc.dg/Wint-conversion-3.c: Likewise. * gcc.dg/Wint-conversion-4.c: New test. Based on gcc.dg/Wint-conversion-3.c. Expect int-conversion errors. * gcc.dg/assign-warn-1.c: Compile with -fpermissive. * gcc.dg/assign-warn-4.c: New file. Extracted from assign-warn1.c. Expect int-cnversion errors. * gcc.dg/diagnostic-types-1.c: compile with -fpermissive. * gcc.dg/diagnostic-types-2.c: New file. Extracted from gcc.dg/diagnostic-types-1.c. Expect some errors instead of warnings. * gcc.dg/gomp/pr35738.c: Compile with -fpermissive due to expected int-conversion error. * gcc.dg/gomp/pr35738-2.c: New test. Based on gcc.dg/gomp/pr35738.c. Expect int-converison errors. * gcc.dg/init-excess-3.c: Expect int-converison errors. * gcc.dg/overflow-warn-1.c: Likewise. * gcc.dg/overflow-warn-3.c: Likewise. * gcc.dg/param-type-mismatch.c: Compile with -fpermissive. * gcc.dg/param-type-mismatch-2.c: New test. Copied from gcc.dg/param-type-mismatch.c. Expect errors. * gcc.dg/pr61162-2.c: Compile with -fpermissive. * gcc.dg/pr61162-3.c: New test. Extracted from gcc.dg/pr61162-2.c. Expect int-conversion errors. * gcc.dg/spec-barrier-3.c: Use -fpermissive due to expected int-conversion error. * gcc.dg/spec-barrier-3a.c: New test. Based on gcc.dg/spec-barrier-3.c. Expect int-conversion errors. * gcc.target/aarch64/acle/memtag_2.c: Use -fpermissive due to expected int-conversion error. * gcc.target/aarch64/acle/memtag_2a.c: New test. Copied from gcc.target/aarch64/acle/memtag_2.c. Expect error. * gcc.target/aarch64/sve/acle/general-c/load_3.c (f1): Expect error. * gcc.target/aarch64/sve/acle/general-c/store_2.c (f1): Likewise. * gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c (f1): Likewise. * gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c (f1): Likewise. * gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c (f1): Likewise. * gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c (f1): Likewise. --- gcc/c/c-typeck.cc | 97 +++++---- gcc/doc/invoke.texi | 6 + gcc/testsuite/c-c++-common/pr77624-1.c | 4 +- gcc/testsuite/gcc.dg/Wint-conversion-2.c | 2 +- gcc/testsuite/gcc.dg/Wint-conversion-3.c | 2 +- gcc/testsuite/gcc.dg/Wint-conversion-4.c | 14 ++ gcc/testsuite/gcc.dg/assign-warn-1.c | 2 +- gcc/testsuite/gcc.dg/assign-warn-4.c | 21 ++ gcc/testsuite/gcc.dg/diagnostic-types-1.c | 2 +- gcc/testsuite/gcc.dg/diagnostic-types-2.c | 24 +++ gcc/testsuite/gcc.dg/gomp/pr35738-2.c | 18 ++ gcc/testsuite/gcc.dg/gomp/pr35738.c | 2 +- gcc/testsuite/gcc.dg/init-excess-3.c | 4 +- gcc/testsuite/gcc.dg/overflow-warn-1.c | 4 +- gcc/testsuite/gcc.dg/overflow-warn-3.c | 4 +- gcc/testsuite/gcc.dg/param-type-mismatch-2.c | 187 ++++++++++++++++++ gcc/testsuite/gcc.dg/param-type-mismatch.c | 2 +- gcc/testsuite/gcc.dg/permerror-default.c | 20 +- gcc/testsuite/gcc.dg/permerror-system.c | 13 +- gcc/testsuite/gcc.dg/pr61162-2.c | 2 +- gcc/testsuite/gcc.dg/pr61162-3.c | 13 ++ gcc/testsuite/gcc.dg/spec-barrier-3.c | 2 +- gcc/testsuite/gcc.dg/spec-barrier-3a.c | 13 ++ .../gcc.target/aarch64/acle/memtag_2.c | 4 +- .../gcc.target/aarch64/acle/memtag_2a.c | 71 +++++++ .../aarch64/sve/acle/general-c/load_3.c | 2 +- .../aarch64/sve/acle/general-c/store_2.c | 2 +- .../acle/general-c/store_scatter_index_1.c | 2 +- .../store_scatter_index_restricted_1.c | 2 +- .../acle/general-c/store_scatter_offset_2.c | 2 +- .../store_scatter_offset_restricted_1.c | 2 +- 31 files changed, 473 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wint-conversion-4.c create mode 100644 gcc/testsuite/gcc.dg/assign-warn-4.c create mode 100644 gcc/testsuite/gcc.dg/diagnostic-types-2.c create mode 100644 gcc/testsuite/gcc.dg/gomp/pr35738-2.c create mode 100644 gcc/testsuite/gcc.dg/param-type-mismatch-2.c create mode 100644 gcc/testsuite/gcc.dg/pr61162-3.c create mode 100644 gcc/testsuite/gcc.dg/spec-barrier-3a.c create mode 100644 gcc/testsuite/gcc.target/aarch64/acle/memtag_2a.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 1dbb4471a88..c7b35a27e3f 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -5450,8 +5450,9 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op2)) - pedwarn (colon_loc, OPT_Wint_conversion, - "pointer/integer type mismatch in conditional expression"); + permerror_opt (colon_loc, OPT_Wint_conversion, + "pointer/integer type mismatch " + "in conditional expression"); else { op2 = null_pointer_node; @@ -5462,8 +5463,9 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op1)) - pedwarn (colon_loc, OPT_Wint_conversion, - "pointer/integer type mismatch in conditional expression"); + permerror_opt (colon_loc, OPT_Wint_conversion, + "pointer/integer type mismatch " + "in conditional expression"); else { op1 = null_pointer_node; @@ -6559,28 +6561,48 @@ error_init (location_t loc, const char *gmsgid, ...) inform (loc, "(near initialization for %qs)", ofwhat); } -/* Issue a pedantic warning for a bad initializer component. OPT is - the option OPT_* (from options.h) controlling this warning or 0 if - it is unconditionally given. GMSGID identifies the message. The - component name is taken from the spelling stack. */ +/* Used to implement pedwarn_init and permerror_init. */ static void ATTRIBUTE_GCC_DIAG (3,0) -pedwarn_init (location_t loc, int opt, const char *gmsgid, ...) +pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid, + va_list *ap, diagnostic_t kind) { /* Use the location where a macro was expanded rather than where it was defined to make sure macros defined in system headers but used incorrectly elsewhere are diagnosed. */ location_t exploc = expansion_point_location_if_in_system_header (loc); auto_diagnostic_group d; - va_list ap; - va_start (ap, gmsgid); - bool warned = emit_diagnostic_valist (DK_PEDWARN, exploc, opt, gmsgid, &ap); - va_end (ap); + bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap); char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); if (*ofwhat && warned) inform (exploc, "(near initialization for %qs)", ofwhat); } +/* Issue a pedantic warning for a bad initializer component. OPT is + the option OPT_* (from options.h) controlling this warning or 0 if + it is unconditionally given. GMSGID identifies the message. The + component name is taken from the spelling stack. */ + +static void ATTRIBUTE_GCC_DIAG (3,0) +pedwarn_init (location_t loc, int opt, const char *gmsgid, ...) +{ + va_list ap; + va_start (ap, gmsgid); + pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PEDWARN); + va_end (ap); +} + +/* Like pedwarn_init, but issue a permerror. */ + +static void ATTRIBUTE_GCC_DIAG (3,0) +permerror_init (location_t loc, int opt, const char *gmsgid, ...) +{ + va_list ap; + va_start (ap, gmsgid); + pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PERMERROR); + va_end (ap); +} + /* Issue a warning for a bad initializer component. OPT is the OPT_W* value corresponding to the warning option that @@ -7630,27 +7652,28 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, auto_diagnostic_group d; range_label_for_type_mismatch rhs_label (rhstype, type); gcc_rich_location richloc (expr_loc, &rhs_label); - if (pedwarn (&richloc, OPT_Wint_conversion, - "passing argument %d of %qE makes pointer from " - "integer without a cast", parmnum, rname)) + if (permerror_opt (&richloc, OPT_Wint_conversion, + "passing argument %d of %qE makes pointer " + "from integer without a cast", parmnum, rname)) inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype); } break; case ic_assign: - pedwarn (location, OPT_Wint_conversion, - "assignment to %qT from %qT makes pointer from integer " - "without a cast", type, rhstype); + permerror_opt (location, OPT_Wint_conversion, + "assignment to %qT from %qT makes pointer from " + "integer without a cast", type, rhstype); break; case ic_init: case ic_init_const: - pedwarn_init (location, OPT_Wint_conversion, - "initialization of %qT from %qT makes pointer from " - "integer without a cast", type, rhstype); + permerror_init (location, OPT_Wint_conversion, + "initialization of %qT from %qT makes pointer " + "from integer without a cast", type, rhstype); break; case ic_return: - pedwarn (location, OPT_Wint_conversion, "returning %qT from a " - "function with return type %qT makes pointer from " - "integer without a cast", rhstype, type); + permerror_init (location, OPT_Wint_conversion, + "returning %qT from a function with return type " + "%qT makes pointer from integer without a cast", + rhstype, type); break; default: gcc_unreachable (); @@ -7668,27 +7691,27 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, auto_diagnostic_group d; range_label_for_type_mismatch rhs_label (rhstype, type); gcc_rich_location richloc (expr_loc, &rhs_label); - if (pedwarn (&richloc, OPT_Wint_conversion, - "passing argument %d of %qE makes integer from " - "pointer without a cast", parmnum, rname)) + if (permerror_opt (&richloc, OPT_Wint_conversion, + "passing argument %d of %qE makes integer from " + "pointer without a cast", parmnum, rname)) inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype); } break; case ic_assign: - pedwarn (location, OPT_Wint_conversion, - "assignment to %qT from %qT makes integer from pointer " - "without a cast", type, rhstype); + permerror_opt (location, OPT_Wint_conversion, + "assignment to %qT from %qT makes integer from " + "pointer without a cast", type, rhstype); break; case ic_init: case ic_init_const: - pedwarn_init (location, OPT_Wint_conversion, - "initialization of %qT from %qT makes integer from " - "pointer without a cast", type, rhstype); + permerror_init (location, OPT_Wint_conversion, + "initialization of %qT from %qT makes integer " + "from pointer without a cast", type, rhstype); break; case ic_return: - pedwarn (location, OPT_Wint_conversion, "returning %qT from a " - "function with return type %qT makes integer from " - "pointer without a cast", rhstype, type); + permerror_opt (location, OPT_Wint_conversion, "returning %qT from a " + "function with return type %qT makes integer from " + "pointer without a cast", rhstype, type); break; default: gcc_unreachable (); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 2d30a5d4767..6f748c3efd2 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6179,6 +6179,7 @@ only by this flag, but it also downgrades some C and C++ diagnostics that have their own flag: @gccoptlist{ +-Wint-conversion @r{(C)} -Wnarrowing @r{(C++)} } @@ -8545,6 +8546,11 @@ conversions. This warning is about implicit conversions; for explicit conversions the warnings @option{-Wno-int-to-pointer-cast} and @option{-Wno-pointer-to-int-cast} may be used. +By default, in C99 and later dialects of C, GCC treats this issue as an +error. 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=int-conversion}. + This warning is upgraded to an error by @option{-pedantic-errors}. @opindex Wzero-length-bounds diff --git a/gcc/testsuite/c-c++-common/pr77624-1.c b/gcc/testsuite/c-c++-common/pr77624-1.c index 3567e9b866f..e25469ee2c1 100644 --- a/gcc/testsuite/c-c++-common/pr77624-1.c +++ b/gcc/testsuite/c-c++-common/pr77624-1.c @@ -4,11 +4,11 @@ int foo (int a) { - return __atomic_is_lock_free (2, a); /* { dg-warning "pointer from integer" "" { target c } } */ + return __atomic_is_lock_free (2, a); /* { dg-error "pointer from integer" "" { target c } } */ } /* { dg-error "invalid conversion" "" { target c++ } .-1 } */ int bar (int a) { - return __atomic_always_lock_free (2, a); /* { dg-warning "pointer from integer" "" { target c } } */ + return __atomic_always_lock_free (2, a); /* { dg-error "pointer from integer" "" { target c } } */ } /* { dg-error "invalid conversion" "" { target c++ } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/Wint-conversion-2.c b/gcc/testsuite/gcc.dg/Wint-conversion-2.c index bf590a7bcd7..101e792e5b6 100644 --- a/gcc/testsuite/gcc.dg/Wint-conversion-2.c +++ b/gcc/testsuite/gcc.dg/Wint-conversion-2.c @@ -1,7 +1,7 @@ /* PR middle-end/86202 - ICE in get_range_info calling an invalid memcpy() declaration */ /* { dg-do compile } */ -/* { dg-options "-Wint-conversion" } */ +/* { dg-options "-fpermissive -Wint-conversion" } */ void *memcpy (void *, void *, __SIZE_TYPE__ *); /* { dg-warning "conflicting types for built-in function .memcpy." } */ void *a, *b; diff --git a/gcc/testsuite/gcc.dg/Wint-conversion-3.c b/gcc/testsuite/gcc.dg/Wint-conversion-3.c index 4e514769c01..4614c015db4 100644 --- a/gcc/testsuite/gcc.dg/Wint-conversion-3.c +++ b/gcc/testsuite/gcc.dg/Wint-conversion-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-fpermissive" } */ const char * f1 (int flag) diff --git a/gcc/testsuite/gcc.dg/Wint-conversion-4.c b/gcc/testsuite/gcc.dg/Wint-conversion-4.c new file mode 100644 index 00000000000..6ded61aed9c --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-conversion-4.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +const char * +f1 (int flag) +{ + return flag ? "" : 1; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +} + +const char * +f2 (int flag) +{ + return flag ? 1 : ""; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +} diff --git a/gcc/testsuite/gcc.dg/assign-warn-1.c b/gcc/testsuite/gcc.dg/assign-warn-1.c index 365025724c4..c483276a913 100644 --- a/gcc/testsuite/gcc.dg/assign-warn-1.c +++ b/gcc/testsuite/gcc.dg/assign-warn-1.c @@ -1,7 +1,7 @@ /* Test diagnostics for bad implicit type conversions. */ /* Origin: Joseph Myers */ /* { dg-do compile } */ -/* { dg-options "-pedantic -ftrack-macro-expansion=0" } */ +/* { dg-options "-pedantic -fpermissive -ftrack-macro-expansion=0" } */ #define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy #define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy diff --git a/gcc/testsuite/gcc.dg/assign-warn-4.c b/gcc/testsuite/gcc.dg/assign-warn-4.c new file mode 100644 index 00000000000..da834f7d29d --- /dev/null +++ b/gcc/testsuite/gcc.dg/assign-warn-4.c @@ -0,0 +1,21 @@ +/* Test diagnostics for bad implicit type conversions. Error variant. */ +/* { dg-do compile } */ +/* { dg-options "-ftrack-macro-expansion=0" } */ + +#define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy +#define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy +#define TESTASS(ID, TL, TR) void ID##F(TR x) { TL y; y = x; } extern int dummy +#define TESTINI(ID, TL, TR) void ID##F(TR x) { TL y = x; } extern int dummy +#define TESTRET(ID, TL, TR) TR ID##V; TL ID##F(void) { return ID##V; } extern int dummy + +TESTARG(ciia, char *, int); /* { dg-error "passing argument 1 of 'ciiaF' makes pointer from integer without a cast" } */ +TESTARP(ciib, char *, int); /* { dg-error "passing argument 1 of 'ciibFp.x' makes pointer from integer without a cast" } */ +TESTASS(ciic, char *, int); /* { dg-error "assignment to 'char \\*' from 'int' makes pointer from integer without a cast" } */ +TESTINI(ciid, char *, int); /* { dg-error "initialization of 'char \\*' from 'int' makes pointer from integer without a cast" } */ +TESTRET(ciie, char *, int); /* { dg-error "returning 'int' from a function with return type 'char \\*' makes pointer from integer without a cast" } */ + +TESTARG(iica, int, char *); /* { dg-error "passing argument 1 of 'iicaF' makes integer from pointer without a cast" } */ +TESTARP(iicb, int, char *); /* { dg-error "passing argument 1 of 'iicbFp.x' makes integer from pointer without a cast" } */ +TESTASS(iicc, int, char *); /* { dg-error "assignment to 'int' from 'char \\*' makes integer from pointer without a cast" } */ +TESTINI(iicd, int, char *); /* { dg-error "initialization of 'int' from 'char \\*' makes integer from pointer without a cast" } */ +TESTRET(iice, int, char *); /* { dg-error "returning 'char \\*' from a function with return type 'int' makes integer from pointer without a cast" } */ diff --git a/gcc/testsuite/gcc.dg/diagnostic-types-1.c b/gcc/testsuite/gcc.dg/diagnostic-types-1.c index fc4b104df05..94b67c6ae8d 100644 --- a/gcc/testsuite/gcc.dg/diagnostic-types-1.c +++ b/gcc/testsuite/gcc.dg/diagnostic-types-1.c @@ -1,6 +1,6 @@ /* PR c/81233 */ /* { dg-do compile } */ -/* { dg-options "-Wc++-compat -Wpedantic" } */ +/* { dg-options "-fpermissive -Wc++-compat -Wpedantic" } */ /* Test we're printing the types, like the good compiler we are. */ enum E1 { A } e; diff --git a/gcc/testsuite/gcc.dg/diagnostic-types-2.c b/gcc/testsuite/gcc.dg/diagnostic-types-2.c new file mode 100644 index 00000000000..e6d284d2c5f --- /dev/null +++ b/gcc/testsuite/gcc.dg/diagnostic-types-2.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ +/* Test we're printing the types, like the good compiler we are. */ + +extern void foo2 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'int'" } */ +extern void foo3 (int); /* { dg-message "expected 'int' but argument is of type 'int \\*'" } */ + +int * +fn1 (int *p) +{ + p = 1; /* { dg-error "assignment to 'int \\*' from 'int' makes pointer from integer without a cast" } */ + int *q = 1; /* { dg-error "initialization of 'int \\*' from 'int' makes pointer from integer without a cast" } */ + foo2 (1); /* { dg-error "passing argument 1 of 'foo2' makes pointer from integer without a cast" } */ + return 1; /* { dg-error "returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */ +} + +int +fn2 (int i, int *p) +{ + i = p; /* { dg-error "assignment to 'int' from 'int \\*' makes integer from pointer without a cast" } */ + int j = p; /* { dg-error "initialization of 'int' from 'int \\*' makes integer from pointer without a cast" } */ + foo3 (p); /* { dg-error "passing argument 1 of 'foo3' makes integer from pointer without a cast" } */ + return p; /* { dg-error "returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */ +} diff --git a/gcc/testsuite/gcc.dg/gomp/pr35738-2.c b/gcc/testsuite/gcc.dg/gomp/pr35738-2.c new file mode 100644 index 00000000000..846afe7e778 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/pr35738-2.c @@ -0,0 +1,18 @@ +/* PR c/35738 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp" } */ + +void foo (void); + +void +bar (void *p) +{ + int i = 0; + char q[10]; +#pragma omp atomic + i += q; /* { dg-error "makes integer from pointer without a cast" } */ +#pragma omp atomic + i += foo; /* { dg-error "makes integer from pointer without a cast" } */ +#pragma omp atomic + i += p; /* { dg-error "makes integer from pointer without a cast" } */ +} diff --git a/gcc/testsuite/gcc.dg/gomp/pr35738.c b/gcc/testsuite/gcc.dg/gomp/pr35738.c index 0b3866eae3b..954cfa43ece 100644 --- a/gcc/testsuite/gcc.dg/gomp/pr35738.c +++ b/gcc/testsuite/gcc.dg/gomp/pr35738.c @@ -1,6 +1,6 @@ /* PR c/35738 */ /* { dg-do compile } */ -/* { dg-options "-fopenmp" } */ +/* { dg-options "-fpermissive -fopenmp" } */ void foo (void); diff --git a/gcc/testsuite/gcc.dg/init-excess-3.c b/gcc/testsuite/gcc.dg/init-excess-3.c index c03a98487b4..6ea7858a1c9 100644 --- a/gcc/testsuite/gcc.dg/init-excess-3.c +++ b/gcc/testsuite/gcc.dg/init-excess-3.c @@ -7,9 +7,9 @@ char s0[] = {"abc",1}; /* { dg-error "'char..' initializer|near init" } */ char s1[] = {"abc","a"}; /* { dg-error "'char..' initializer|near init" } */ char s2[] = {1,"abc"}; /* { dg-error "'char..' initializer|near init|computable at load time" } */ -/* { dg-warning "integer from pointer without a cast" "" { target *-*-* } .-1 } */ +/* { dg-error "integer from pointer without a cast" "" { target *-*-* } .-1 } */ char s3[5] = {"abc",1}; /* { dg-error "'char.5.' initializer|near init" } */ char s4[5] = {"abc","a"}; /* { dg-error "'char.5.' initializer|near init" } */ char s5[5] = {1,"abc"}; /* { dg-error "'char.5.' initializer|near init|computable at load time" } */ -/* { dg-warning "integer from pointer without a cast" "" { target *-*-* } .-1 } */ +/* { dg-error "integer from pointer without a cast" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/overflow-warn-1.c b/gcc/testsuite/gcc.dg/overflow-warn-1.c index a9d9fbae148..90eb43b35e2 100644 --- a/gcc/testsuite/gcc.dg/overflow-warn-1.c +++ b/gcc/testsuite/gcc.dg/overflow-warn-1.c @@ -47,10 +47,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "25:integer overflow in expression" constants. The third has the overflow in an unevaluated subexpression, so is a null pointer constant. */ void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ -/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */ +/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */ void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */ /* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */ -/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ +/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ void *r = (1 ? 0 : INT_MAX+1); void diff --git a/gcc/testsuite/gcc.dg/overflow-warn-3.c b/gcc/testsuite/gcc.dg/overflow-warn-3.c index f64047795c7..a2ead836964 100644 --- a/gcc/testsuite/gcc.dg/overflow-warn-3.c +++ b/gcc/testsuite/gcc.dg/overflow-warn-3.c @@ -53,10 +53,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } subexpression, so is a null pointer constant. */ void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } .-1 } */ -/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ +/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */ /* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */ -/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ +/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */ void *r = (1 ? 0 : INT_MAX+1); void diff --git a/gcc/testsuite/gcc.dg/param-type-mismatch-2.c b/gcc/testsuite/gcc.dg/param-type-mismatch-2.c new file mode 100644 index 00000000000..91d998437d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/param-type-mismatch-2.c @@ -0,0 +1,187 @@ +/* { dg-options "-fdiagnostics-show-caret -Wpointer-sign" } */ + +/* A collection of calls where argument 2 is of the wrong type. + Like param-type-mismatch.c, but expecting errors. */ + +/* decl, with argname. */ + +extern int callee_1 (int one, const char *two, float three); /* { dg-line callee_1 } */ + +int test_1 (int first, int second, float third) +{ + return callee_1 (first, second, third); /* { dg-error "passing argument 2 of 'callee_1' makes pointer from integer without a cast" } */ + /* { dg-begin-multiline-output "" } + return callee_1 (first, second, third); + ^~~~~~ + | + int + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_1 } */ + /* { dg-begin-multiline-output "" } + extern int callee_1 (int one, const char *two, float three); + ~~~~~~~~~~~~^~~ + { dg-end-multiline-output "" } */ +} + +/* decl, without argname. */ + +extern int callee_2 (int, const char *, float); /* { dg-line callee_2 } */ + +int test_2 (int first, int second, float third) +{ + return callee_2 (first, second, third); /* { dg-error "passing argument 2 of 'callee_2' makes pointer from integer without a cast" } */ + /* { dg-begin-multiline-output "" } + return callee_2 (first, second, third); + ^~~~~~ + | + int + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_2 } */ + /* { dg-begin-multiline-output "" } + extern int callee_2 (int, const char *, float); + ^~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +/* defn, with argname. */ + +static int callee_3 (int one, const char *two, float three) /* { dg-line callee_3 } */ +{ + return callee_2 (one, two, three); +} + +int test_3 (int first, int second, float third) +{ + return callee_3 (first, second, third); // { dg-error "passing argument 2 of 'callee_3' makes pointer from integer without a cast" } + /* { dg-begin-multiline-output "" } + return callee_3 (first, second, third); + ^~~~~~ + | + int + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'const char \\*' but argument is of type 'int'" "" { target *-*-* } callee_3 } */ + /* { dg-begin-multiline-output "" } + static int callee_3 (int one, const char *two, float three) + ~~~~~~~~~~~~^~~ + { dg-end-multiline-output "" } */ +} + +/* Trivial decl, with argname. */ + +extern int callee_4 (int one, float two, float three); /* { dg-line callee_4 } */ + +int test_4 (int first, const char *second, float third) +{ + return callee_4 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_4'" } */ + /* { dg-begin-multiline-output "" } + return callee_4 (first, second, third); + ^~~~~~ + | + const char * + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_4 } */ + /* { dg-begin-multiline-output "" } + extern int callee_4 (int one, float two, float three); + ~~~~~~^~~ + { dg-end-multiline-output "" } */ +} + +/* Trivial decl, without argname. */ + +extern int callee_5 (int, float, float); /* { dg-line callee_5 } */ + +int test_5 (int first, const char *second, float third) +{ + return callee_5 (first, second, third); /* { dg-error "incompatible type for argument 2 of 'callee_5'" } */ + /* { dg-begin-multiline-output "" } + return callee_5 (first, second, third); + ^~~~~~ + | + const char * + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'float' but argument is of type 'const char \\*'" "" { target *-*-* } callee_5 } */ + /* { dg-begin-multiline-output "" } + extern int callee_5 (int, float, float); + ^~~~~ + { dg-end-multiline-output "" } */ +} + +/* Callback with name. */ + +extern int callee_6 (int one, int (*two)(int, int), float three); /* { dg-line callee_6 } */ + +int test_6 (int first, int second, float third) +{ + return callee_6 (first, second, third); /* { dg-error "passing argument 2 of 'callee_6' makes pointer from integer without a cast" } */ + /* { dg-begin-multiline-output "" } + return callee_6 (first, second, third); + ^~~~~~ + | + int + { dg-end-multiline-output "" } */ + /* { dg-message " expected 'int \\(\\*\\)\\(int, int\\)' but argument is of type 'int'" "" { target *-*-* } callee_6 } */ + /* { dg-begin-multiline-output "" } + extern int callee_6 (int one, int (*two)(int, int), float three); + ~~~~~~^~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +/* Callback without name. */ + +extern int callee_7 (int one, int (*)(int, int), float three); /* { dg-line callee_7 } */ + +int test_7 (int first, int second, float third) +{ + return callee_7 (first, second, third); /* { dg-error "passing argument 2 of 'callee_7' makes pointer from integer without a cast" } */ + /* { dg-begin-multiline-output "" } + return callee_7 (first, second, third); + ^~~~~~ + | + int + { dg-end-multiline-output "" } */ + /* { dg-message " expected 'int \\(\\*\\)\\(int, int\\)' but argument is of type 'int'" "" { target *-*-* } callee_7 } */ + /* { dg-begin-multiline-output "" } + extern int callee_7 (int one, int (*)(int, int), float three); + ^~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} + +/* -Wincompatible-pointer-types for a parameter. */ + +extern int callee_8 (int one, float *two, float (three)); /* { dg-line callee_8 } */ + +int test_8 (int first, int *second, float third) +{ + return callee_8 (first, second, third); /* { dg-warning "passing argument 2 of 'callee_8' from incompatible pointer type" } */ + /* { dg-begin-multiline-output "" } + return callee_8 (first, second, third); + ^~~~~~ + | + int * + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'float \\*' but argument is of type 'int \\*'" "" { target *-*-* } callee_8 } */ + /* { dg-begin-multiline-output "" } + extern int callee_8 (int one, float *two, float (three)); + ~~~~~~~^~~ + { dg-end-multiline-output "" } */ +} + +/* -Wpointer-sign for a parameter. */ + +extern int callee_9 (int one, int *two, float (three)); /* { dg-line callee_9 } */ + +int test_9 (int first, unsigned int *second, float third) +{ + return callee_9 (first, second, third); /* { dg-warning "pointer targets in passing argument 2 of 'callee_9' differ in signedness" } */ + /* { dg-begin-multiline-output "" } + return callee_9 (first, second, third); + ^~~~~~ + | + unsigned int * + { dg-end-multiline-output "" } */ + /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" "" { target *-*-* } callee_9 } */ + /* { dg-begin-multiline-output "" } + extern int callee_9 (int one, int *two, float (three)); + ~~~~~^~~ + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/gcc.dg/param-type-mismatch.c b/gcc/testsuite/gcc.dg/param-type-mismatch.c index 9e654a9e9c6..f6d68749cd8 100644 --- a/gcc/testsuite/gcc.dg/param-type-mismatch.c +++ b/gcc/testsuite/gcc.dg/param-type-mismatch.c @@ -1,4 +1,4 @@ -/* { dg-options "-fdiagnostics-show-caret -Wpointer-sign" } */ +/* { dg-options "-fpermissive -fdiagnostics-show-caret -Wpointer-sign" } */ /* A collection of calls where argument 2 is of the wrong type. */ diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c index ea0be1dc89f..5235a427175 100644 --- a/gcc/testsuite/gcc.dg/permerror-default.c +++ b/gcc/testsuite/gcc.dg/permerror-default.c @@ -26,26 +26,26 @@ int * int_conversion_1 (int flag) { void f2 (int *); - flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ - flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ - f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ + flag ? "1" : 1; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ + flag ? 1 : "1"; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ + f2 (flag); /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ { - int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ - i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ + int i1 = &flag; /* { dg-error "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ + i1 = &flag; /* { dg-error "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ } - return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ + return flag; /* { dg-error "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ } int int_conversion_2 (int flag) { void f3 (int); - f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ + f3 (&flag); /* { dg-error "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ { - int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ - i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ + int *i1 = flag; /* { dg-error "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ + i1 = flag; /* { dg-error "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */ } - return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ + return &flag; /* { dg-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ } int * diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c index e6a978e494d..75e08887ef1 100644 --- a/gcc/testsuite/gcc.dg/permerror-system.c +++ b/gcc/testsuite/gcc.dg/permerror-system.c @@ -6,4 +6,15 @@ expected. */ #include -/* These errors come from permerror-default.c. No errors yet. */ +/* These errors come from permerror-default.c. */ + +/* { 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 } */ +/* { dg-error "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 33 } */ +/* { dg-error "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 34 } */ +/* { dg-error "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 36 } */ +/* { dg-error "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 43 } */ +/* { dg-error "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 45 } */ +/* { dg-error "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 46 } */ +/* { dg-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 48 } */ diff --git a/gcc/testsuite/gcc.dg/pr61162-2.c b/gcc/testsuite/gcc.dg/pr61162-2.c index 4aa8493d1a3..a7d0b45a310 100644 --- a/gcc/testsuite/gcc.dg/pr61162-2.c +++ b/gcc/testsuite/gcc.dg/pr61162-2.c @@ -1,6 +1,6 @@ /* PR c/61162 */ /* { dg-do compile } */ -/* { dg-options "-Wc++-compat -Wpointer-sign -Wpedantic" } */ +/* { dg-options "-fpermissive -Wc++-compat -Wpointer-sign -Wpedantic" } */ enum e { A }; struct s { int a; }; diff --git a/gcc/testsuite/gcc.dg/pr61162-3.c b/gcc/testsuite/gcc.dg/pr61162-3.c new file mode 100644 index 00000000000..c48625797d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr61162-3.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +int +fn4 (int *a) +{ + return a; /* { dg-error "10:returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */ +} + +int * +fn5 (int a) +{ + return a; /* { dg-error "10:returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */ +} diff --git a/gcc/testsuite/gcc.dg/spec-barrier-3.c b/gcc/testsuite/gcc.dg/spec-barrier-3.c index 3ed4d39061a..0940a2105c6 100644 --- a/gcc/testsuite/gcc.dg/spec-barrier-3.c +++ b/gcc/testsuite/gcc.dg/spec-barrier-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Wpedantic" } */ +/* { dg-options "-fpermissive -Wpedantic" } */ /* __builtin_speculation_safe_value returns a value with the same type as its first argument. There should be a warning if that isn't diff --git a/gcc/testsuite/gcc.dg/spec-barrier-3a.c b/gcc/testsuite/gcc.dg/spec-barrier-3a.c new file mode 100644 index 00000000000..ee98ad0ca50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/spec-barrier-3a.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ + +/* __builtin_speculation_safe_value returns a value with the same type + as its first argument. There should be an error if that isn't + type-compatible with the use. */ +int * +f (int x) +{ + return __builtin_speculation_safe_value (x); /* { dg-error "returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */ +} + +/* { dg-prune-output "this target does not define a speculation barrier;" } */ diff --git a/gcc/testsuite/gcc.target/aarch64/acle/memtag_2.c b/gcc/testsuite/gcc.target/aarch64/acle/memtag_2.c index fcab05b7abe..806e0750fd1 100644 --- a/gcc/testsuite/gcc.target/aarch64/acle/memtag_2.c +++ b/gcc/testsuite/gcc.target/aarch64/acle/memtag_2.c @@ -2,7 +2,7 @@ /* { dg-do compile } */ /* { dg-require-effective-target lp64 } */ -/* { dg-options "-O3 -march=armv8.5-a+memtag" } */ +/* { dg-options "-fpermissive -O3 -march=armv8.5-a+memtag" } */ #include "arm_acle.h" @@ -67,4 +67,4 @@ test_memtag_error_argument (void) __arm_mte_ptrdiff(no_decl2, 0); /* { dg-error {} } */ __arm_mte_ptrdiff(0); /* { dg-error {} } */ __arm_mte_ptrdiff(); /* { dg-error {} } */ -} \ No newline at end of file +} diff --git a/gcc/testsuite/gcc.target/aarch64/acle/memtag_2a.c b/gcc/testsuite/gcc.target/aarch64/acle/memtag_2a.c new file mode 100644 index 00000000000..16db40df663 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/acle/memtag_2a.c @@ -0,0 +1,71 @@ +/* Test the MEMTAG intrinsic qualifier warnings and argument errors. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O3 -march=armv8.5-a+memtag" } */ + +#include "arm_acle.h" + +void +test_memtag_warning_return_qualifier (void) +{ + const char *c; + volatile char *v; + char *n; + int *i; + int64_t d; + + v = __arm_mte_get_tag(c); /* { dg-warning {assignment} } */ + n = __arm_mte_get_tag(c); /* { dg-warning {assignment} } */ + i = __arm_mte_get_tag(c); /* { dg-warning {assignment} } */ + c = __arm_mte_get_tag(v); /* { dg-warning {assignment} } */ + n = __arm_mte_get_tag(v); /* { dg-warning {assignment} } */ + + i = __arm_mte_create_random_tag (c, 0); /* { dg-warning {assignment} } */ + i = __arm_mte_increment_tag (c, 0); /* { dg-warning {assignment} } */ + + c = __arm_mte_get_tag(n); /* No warning. */ + d = __arm_mte_ptrdiff(c, i); /* No warning. */ +} + +void +test_memtag_warning_argument (void) +{ + const char *c; + __arm_mte_exclude_tag(0, 0); /* No warning. */ + __arm_mte_create_random_tag (0, 0); /* No warning. */ + __arm_mte_set_tag(0); /* No warning. */ + __arm_mte_get_tag(0); /* No warning. */ + __arm_mte_increment_tag (0, 15); /* No warning. */ + __arm_mte_ptrdiff(c, 0); /* No warning. */ + __arm_mte_ptrdiff(0, c); /* No warning. */ +} + +void +test_memtag_error_argument (void) +{ + /* Produce errors properly for invalid arguments. */ + __arm_mte_exclude_tag(no_decl, 0); /* { dg-error {} } */ + __arm_mte_exclude_tag(); /* { dg-error {} } */ + __arm_mte_ptrdiff(no_decl2, 0); /* { dg-error {} } */ + __arm_mte_ptrdiff(0); /* { dg-error {} } */ + __arm_mte_ptrdiff(); /* { dg-error {} } */ + + const char *c; + uint64_t i; + __arm_mte_exclude_tag(i, 0); /* { dg-error {argument} } */ + __arm_mte_create_random_tag (i, 0); /* { dg-error {argument} } */ + __arm_mte_set_tag(i); /* { dg-error {argument} } */ + __arm_mte_get_tag(i); /* { dg-error {argument} } */ + __arm_mte_increment_tag (i, 15); /* { dg-error {argument} } */ + __arm_mte_ptrdiff(c, i); /* { dg-error {argument} } */ + __arm_mte_ptrdiff(i, c); /* { dg-error {argument} } */ + + __arm_mte_exclude_tag(1, 0); /* { dg-error {argument} } */ + __arm_mte_create_random_tag (1, 0); /* { dg-error {argument} } */ + __arm_mte_set_tag(1); /* { dg-error {argument} } */ + __arm_mte_get_tag(1); /* { dg-error {argument} } */ + __arm_mte_increment_tag (1, 15); /* { dg-error {argument} } */ + __arm_mte_ptrdiff(c, 1); /* { dg-error {argument} } */ + __arm_mte_ptrdiff(1, c); /* { dg-error {argument} } */ +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/load_3.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/load_3.c index 770203f64c8..34166395ecc 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/load_3.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/load_3.c @@ -13,6 +13,6 @@ f1 (svbool_t pg, signed char *s8_ptr, svint8_t s8) svld1_vnum (pg, s8_ptr, 0, 0); /* { dg-error {too many arguments to function 'svld1_vnum'} } */ svld1_vnum (0, s8_ptr, 0); /* { dg-error {passing 'int' to argument 1 of 'svld1_vnum', which expects 'svbool_t'} } */ svld1_vnum (pg, 0, 0); /* { dg-error {passing 'int' to argument 2 of 'svld1_vnum', which expects a pointer type} } */ - svld1_vnum (pg, s8_ptr, s8_ptr); /* { dg-warning "passing argument 3 of 'svld1_vnum_s8' makes integer from pointer without a cast" } */ + svld1_vnum (pg, s8_ptr, s8_ptr); /* { dg-error "passing argument 3 of 'svld1_vnum_s8' makes integer from pointer without a cast" } */ svld1_vnum (pg, s8_ptr, s8); /* { dg-error {passing 'svint8_t' to argument 3 of 'svld1_vnum', which expects 'int64_t'} } */ } diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_2.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_2.c index c718b3ee04e..669f8844bc1 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_2.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_2.c @@ -14,7 +14,7 @@ f1 (svbool_t pg, signed char *s8_ptr, void *void_ptr, struct s *s_ptr, svst1_vnum (0, s8_ptr, 0, s8); /* { dg-error {passing 'int' to argument 1 of 'svst1_vnum', which expects 'svbool_t'} } */ svst1_vnum (pg, s8_ptr, pg, s8); /* { dg-error {passing 'svbool_t' to argument 3 of 'svst1_vnum', which expects 'int64_t'} } */ svst1_vnum (pg, s8_ptr, s8, s8); /* { dg-error {passing 'svint8_t' to argument 3 of 'svst1_vnum', which expects 'int64_t'} } */ - svst1_vnum (pg, s8_ptr, void_ptr, s8); /* { dg-warning "passing argument 3 of 'svst1_vnum_s8' makes integer from pointer without a cast" } */ + svst1_vnum (pg, s8_ptr, void_ptr, s8); /* { dg-error "passing argument 3 of 'svst1_vnum_s8' makes integer from pointer without a cast" } */ svst1_vnum (pg, void_ptr, 0, 0); /* { dg-error {passing 'int' to argument 4 of 'svst1_vnum', which expects an SVE vector type} } */ svst1_vnum (pg, void_ptr, 0, pg); /* { dg-error {'svst1_vnum' has no form that takes 'svbool_t' arguments} } */ svst1_vnum (pg, 0, 0, s8); diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c index 89528237522..29f4510c49b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_1.c @@ -26,7 +26,7 @@ f1 (svbool_t pg, signed char *s8_ptr, short *s16_ptr, svst1_scatter_index (pg, cf32_ptr, s32, f32); /* { dg-warning "passing argument 2 of 'svst1_scatter_s32index_f32' from incompatible pointer type" } */ svst1_scatter_index (pg, s, s32, s32); /* { dg-error {passing 'struct s' to argument 2 of 'svst1_scatter_index', which expects a vector or pointer base address} } */ - svst1_scatter_index (pg, u32, void_ptr, s32); /* { dg-warning "passing argument 3 of 'svst1_scatter_u32base_index_s32' makes integer from pointer without a cast" } */ + svst1_scatter_index (pg, u32, void_ptr, s32); /* { dg-error "passing argument 3 of 'svst1_scatter_u32base_index_s32' makes integer from pointer without a cast" } */ svst1_scatter_index (pg, u32, pg, s32); /* { dg-error {passing 'svbool_t' to argument 3 of 'svst1_scatter_index', which expects 'int64_t'} } */ svst1_scatter_index (pg, u32, s32, s32); /* { dg-error {passing 'svint32_t' to argument 3 of 'svst1_scatter_index', which expects 'int64_t'} } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c index 5e31362c412..ab718b5eeee 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_index_restricted_1.c @@ -28,7 +28,7 @@ f1 (svbool_t pg, signed char *s8_ptr, short *s16_ptr, svstnt1_scatter_index (pg, cf64_ptr, s64, f64); /* { dg-warning "passing argument 2 of 'svstnt1_scatter_s64index_f64' from incompatible pointer type" } */ svstnt1_scatter_index (pg, s, s64, s64); /* { dg-error {passing 'struct s' to argument 2 of 'svstnt1_scatter_index', which expects a vector or pointer base address} } */ - svstnt1_scatter_index (pg, u32, void_ptr, s32); /* { dg-warning "passing argument 3 of 'svstnt1_scatter_u32base_index_s32' makes integer from pointer without a cast" } */ + svstnt1_scatter_index (pg, u32, void_ptr, s32); /* { dg-error "passing argument 3 of 'svstnt1_scatter_u32base_index_s32' makes integer from pointer without a cast" } */ svstnt1_scatter_index (pg, u32, pg, s32); /* { dg-error {passing 'svbool_t' to argument 3 of 'svstnt1_scatter_index', which expects 'int64_t'} } */ svstnt1_scatter_index (pg, u32, s32, s32); /* { dg-error {passing 'svint32_t' to argument 3 of 'svstnt1_scatter_index', which expects 'int64_t'} } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c index 4854818cae6..311b1744c91 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_2.c @@ -26,7 +26,7 @@ f1 (svbool_t pg, signed char *s8_ptr, short *s16_ptr, svst1_scatter_offset (pg, cf32_ptr, s32, f32); /* { dg-warning "passing argument 2 of 'svst1_scatter_s32offset_f32' from incompatible pointer type" } */ svst1_scatter_offset (pg, s, s32, s32); /* { dg-error {passing 'struct s' to argument 2 of 'svst1_scatter_offset', which expects a vector or pointer base address} } */ - svst1_scatter_offset (pg, u32, void_ptr, s32); /* { dg-warning "passing argument 3 of 'svst1_scatter_u32base_offset_s32' makes integer from pointer without a cast" } */ + svst1_scatter_offset (pg, u32, void_ptr, s32); /* { dg-error "passing argument 3 of 'svst1_scatter_u32base_offset_s32' makes integer from pointer without a cast" } */ svst1_scatter_offset (pg, u32, pg, s32); /* { dg-error {passing 'svbool_t' to argument 3 of 'svst1_scatter_offset', which expects 'int64_t'} } */ svst1_scatter_offset (pg, u32, s32, s32); /* { dg-error {passing 'svint32_t' to argument 3 of 'svst1_scatter_offset', which expects 'int64_t'} } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c index 100624b7b03..5b251127a47 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/store_scatter_offset_restricted_1.c @@ -28,7 +28,7 @@ f1 (svbool_t pg, signed char *s8_ptr, short *s16_ptr, svstnt1_scatter_offset (pg, cf32_ptr, u32, f32); /* { dg-warning "passing argument 2 of 'svstnt1_scatter_u32offset_f32' from incompatible pointer type" } */ svstnt1_scatter_offset (pg, s, u32, s32); /* { dg-error {passing 'struct s' to argument 2 of 'svstnt1_scatter_offset', which expects a vector or pointer base address} } */ - svstnt1_scatter_offset (pg, u32, void_ptr, s32); /* { dg-warning "passing argument 3 of 'svstnt1_scatter_u32base_offset_s32' makes integer from pointer without a cast" } */ + svstnt1_scatter_offset (pg, u32, void_ptr, s32); /* { dg-error "passing argument 3 of 'svstnt1_scatter_u32base_offset_s32' makes integer from pointer without a cast" } */ svstnt1_scatter_offset (pg, u32, pg, s32); /* { dg-error {passing 'svbool_t' to argument 3 of 'svstnt1_scatter_offset', which expects 'int64_t'} } */ svstnt1_scatter_offset (pg, u32, s32, s32); /* { dg-error {passing 'svint32_t' to argument 3 of 'svstnt1_scatter_offset', which expects 'int64_t'} } */