From patchwork Tue Nov 14 17:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 165033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2094442rwb; Tue, 14 Nov 2023 09:51:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/TFwQ58Ruqg13OsFHcrnDYAlEVgrUWMcaGBSuoc2Jc1SzCPXjrIzYENIgj71jFhaKIrcs X-Received: by 2002:a05:6808:640d:b0:3ac:b73a:757f with SMTP id fg13-20020a056808640d00b003acb73a757fmr10509023oib.39.1699984267844; Tue, 14 Nov 2023 09:51:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699984267; cv=pass; d=google.com; s=arc-20160816; b=IgHXh4+sWN9JeHtn0OLXMSe4glGjm8RkaMrlutne8FU901ekqHqgyh9SCBnKIEJAd5 hWcx5mYDdF31CiCglvMUVvt9br0heYtf3GDxEmtSYzLUaFCtS7p3x9Nt0P2SMhdsMqJy mZ9hjYtHgDz2czrAvUIOBqQD+JKYphhhh1fIgDOsk0adC8rgAcA6MsTHZMltqZQDUTkt x28L5+EE6Xsae9fQhID0OHKb95lNHh5S9B1Oy3M3an2P5FQRMCu+8URjBtEDwl4WIr1a qPOMXBLtHU1kFEuN0dbC2bJLLhys6cLKuKVeWkESxEhis85eKyQMQzvpeRh5P7b841GX VSrw== 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=KhF1k3L4WKN2RTCK6NYyfxDygpOcKS9pP+Mx6dBDN0A=; fh=brrc/l6yGUGxGhv8SjiSoDgfQmQ4atC/Em9G49NRuIw=; b=bWFetd5+9FkPJaqLy8yCmODvYM1AGiFumBxZFyvKE0C83GVXm7W2Wfr+WqkArvcvAH SzEigdYzr/bq2NPMkxTbUgwLeK1xuKA9uqhyrB/yDj8+9foTtJ73K33UCe0el9jtBYyj +apKOwodqpX5/OcBI/8YI9GhAL+n87i0j5hdUEneQvsm0zOxh5Q3vUF1lLxcxgeCWriV 9fUMVwt2XdEpJ/+pbk2u70Tf3agY0ToqnK4BWkRHChz6xq/0C0mCMQe+D++/V1G6ajaH +sRDcao6yrbrI/K3HiqiIlwen4+VbT35LxO96+uq8ihmrbQcgpgxrx2V82zoySo3euEq 8bfw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ICAcmwrQ; 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 d2-20020a05620a240200b0076d7b5dd4bfsi7580724qkn.302.2023.11.14.09.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 09:51:07 -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=ICAcmwrQ; 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 6EEF43858C50 for ; Tue, 14 Nov 2023 17:51:02 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 17CA03858C52 for ; Tue, 14 Nov 2023 17:50:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17CA03858C52 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 17CA03858C52 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=1699984233; cv=none; b=nHj2ZDWargk+IGHDTavyCYr4w7r34NN8FtiQp9FzbnYm9F8TDintdMmj/zUjGxfPn/CPFsFa5aPjFNLw7XxI91pOzAhg7XxByWGmFKebOEp7dSrkv6krBWhR4byfk950mEGQrYRtqIHer3LDDH+O1IJCISu7CgTpiBai64BOnmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699984233; c=relaxed/simple; bh=xjgWYBE7TU84/JaEuN4U9HFL4DSxAoGAgEuG1rW0Fz8=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=OfdEnTpCH+qi9UB1Fj8pu1GHhz63p8f77rzZiO3iN3nSzkwD20rOekRR2dYQnF/Fxa5HUFnzSj06wPh+4TmdfqZByBa3uiV5HC4Gf1mjTVzja443FTc9bvs2y5/1mvGOvsYG4BBu90nqI+G20BhquHQHJBA7MbmMMa5nxUqCKY0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699984229; 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=KhF1k3L4WKN2RTCK6NYyfxDygpOcKS9pP+Mx6dBDN0A=; b=ICAcmwrQN5YxcOMhL0460u62UJe7TI71QJ9qfZ34SfsNgbVGFfIGAKGVdRBzMwHgsYUiPI uySvyIXWqd8L/vRXHUGqoYgvtYL5vQ7KH4RYsZ6+oGasqzjyis9nTrUDmAZbk7pyMoPT7h 09drSaLohuJvy6N9beNjiLowgH1FVjk= 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-370-ttVUqjcINGKUkUOGw1TKYA-1; Tue, 14 Nov 2023 12:50:26 -0500 X-MC-Unique: ttVUqjcINGKUkUOGw1TKYA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 176C68058ED; Tue, 14 Nov 2023 17:50:25 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A98DC1596F; Tue, 14 Nov 2023 17:50:23 +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 1/8] Add tests for validating future C permerrors In-Reply-To: Message-ID: <8cc6c84650efbc55326ccaf82982d493aa5cc5f2.1699983736.git.fweimer@redhat.com> References: X-From-Line: 8cc6c84650efbc55326ccaf82982d493aa5cc5f2 Mon Sep 17 00:00:00 2001 Date: Tue, 14 Nov 2023 18:50:16 +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.8 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, 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 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: 1782562703689918425 X-GMAIL-MSGID: 1782562703689918425 The dg-error directives for gcc.dg/permerror-system.c can be generated using (for the most part at least): perl -ne 'print if s,.*(/\* \{ dg-error .*) } \*/$,$1 "" { target *-*-* } $. } */,' \ < gcc/testsuite/gcc.dg/permerror-default.c gcc/testsuite/ * gcc.dg/permerror-default.c: New test. * gcc.dg/permerror-fpermissive.c: Likewise. * gcc.dg/permerror-gnu89-pedantic.c: Likewise. * gcc.dg/permerror-gnu89.c: Likewise. * gcc.dg/permerror-noerror.c: Likewise. * gcc.dg/permerror-pedantic.c: Likewise. * gcc.dg/permerror-system.c: Likewise. --- gcc/testsuite/gcc.dg/permerror-default.c | 85 +++++++++++++++++++ gcc/testsuite/gcc.dg/permerror-fpermissive.c | 85 +++++++++++++++++++ .../gcc.dg/permerror-gnu89-pedantic.c | 85 +++++++++++++++++++ gcc/testsuite/gcc.dg/permerror-gnu89.c | 85 +++++++++++++++++++ gcc/testsuite/gcc.dg/permerror-noerror.c | 85 +++++++++++++++++++ gcc/testsuite/gcc.dg/permerror-pedantic.c | 85 +++++++++++++++++++ gcc/testsuite/gcc.dg/permerror-system.c | 9 ++ 7 files changed, 519 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/permerror-default.c create mode 100644 gcc/testsuite/gcc.dg/permerror-fpermissive.c create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89.c create mode 100644 gcc/testsuite/gcc.dg/permerror-noerror.c create mode 100644 gcc/testsuite/gcc.dg/permerror-pedantic.c create mode 100644 gcc/testsuite/gcc.dg/permerror-system.c diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c new file mode 100644 index 00000000000..ea0be1dc89f --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-default.c @@ -0,0 +1,85 @@ +/* { dg-options "" } */ + +/* Overview test for C permerrors. This test should be kept in sync with the + other permerror-* tests. If new permerrors are added, test cases should be + added to this and the other files. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-warning "'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 } */ +{ + (const) 0; /* { dg-warning "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" } */ + + +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\\\]" } */ + { + 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\\\]" } */ + } + return flag; /* { dg-warning "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\\\]" } */ + { + 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\\\]" } */ + } + return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/gcc.dg/permerror-fpermissive.c new file mode 100644 index 00000000000..139f35ad1c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive.c @@ -0,0 +1,85 @@ +/* { dg-options "-fpermissive" } */ + +/* Overview test for C permerrors. This test should be kept in sync with the + other permerror-* tests. If new permerrors are added, test cases should be + added to this and the other files. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-warning "'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 } */ +{ + (const) 0; /* { dg-warning "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" } */ + + +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\\\]" } */ + { + 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\\\]" } */ + } + return flag; /* { dg-warning "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\\\]" } */ + { + 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\\\]" } */ + } + return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c new file mode 100644 index 00000000000..465a16f5f9a --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c @@ -0,0 +1,85 @@ +/* { dg-options "-std=gnu89 -pedantic-errors" } */ + +/* Overview test for C permerrors. This test should be kept in sync with the + other permerror-* tests. If new permerrors are added, test cases should be + added to this and the other files. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */ +} + +extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */ +typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */ +extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */ +implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ +/* Directive here in the other files. */ +{ + (const) 0; /* { dg-bogus "-Wimplicit-int" } */ +} + +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */ + + +int * +int_conversion_1 (int flag) +{ + void f2 (int *); + 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-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-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-error "passing argument 1 of 'f3' makes integer from pointer 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-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-error "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-error "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-error "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-error "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-error "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-bogus "-Wreturn-mismatch" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89.c b/gcc/testsuite/gcc.dg/permerror-gnu89.c new file mode 100644 index 00000000000..66f7789269f --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-gnu89.c @@ -0,0 +1,85 @@ +/* { dg-options "-std=gnu89" } */ + +/* Overview test for C permerrors. This test should be kept in sync with the + other permerror-* tests. If new permerrors are added, test cases should be + added to this and the other files. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */ +} + +extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */ +typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */ +extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */ +implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */ +/* Directive here in the other files. */ +{ + (const) 0; /* { dg-bogus "-Wimplicit-int" } */ +} + +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */ + + +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\\\]" } */ + { + 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\\\]" } */ + } + return flag; /* { dg-warning "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\\\]" } */ + { + 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\\\]" } */ + } + return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-bogus "-Wreturn-mismatch" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.dg/permerror-noerror.c new file mode 100644 index 00000000000..cd1c2013cb5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-noerror.c @@ -0,0 +1,85 @@ +/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */ + +/* This test should emulate the effect of -fpermissive by adding all the + -Wno-error= options that are implied by -fpermissive. It needs to be + kept in sync with the other permerror-* tests. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-warning "'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 } */ +{ + (const) 0; /* { dg-warning "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" } */ + + +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\\\]" } */ + { + 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\\\]" } */ + } + return flag; /* { dg-warning "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\\\]" } */ + { + 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\\\]" } */ + } + return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-pedantic.c b/gcc/testsuite/gcc.dg/permerror-pedantic.c new file mode 100644 index 00000000000..852e7daa38d --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-pedantic.c @@ -0,0 +1,85 @@ +/* { dg-options "-pedantic-errors" } */ + +/* Overview test for C permerrors. This test should be kept in sync with the + other permerror-* tests. If new permerrors are added, test cases should be + added to this and the other files. */ + +void +implicit_function_declaration (void) +{ + f1 (); /* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" } */ +} + +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-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */ +} + +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */ + + +int * +int_conversion_1 (int flag) +{ + void f2 (int *); + 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-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-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-error "passing argument 1 of 'f3' makes integer from pointer 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-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */ +} + +int * +incompatible_pointer_types (int flag) +{ + void f4 (int *); + flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p1 = __builtin_abs; /* { dg-error "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p1 = __builtin_abs; /* { dg-error "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + } + { + int *p2 = incompatible_pointer_types; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + p2 = incompatible_pointer_types; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */ + { + int *p3 = &p2; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + p3 = &p2; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + } + f4 (&p2); /* { dg-error "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */ + } + if (flag) + return __builtin_abs; /* { dg-error "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ + else + return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */ +} + +void +return_mismatch_1 (void) +{ + return 0; /* { dg-error "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */ +} + +int +return_mismatch_2 (void) +{ + return; /* { dg-error "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */ +} diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c new file mode 100644 index 00000000000..e6a978e494d --- /dev/null +++ b/gcc/testsuite/gcc.dg/permerror-system.c @@ -0,0 +1,9 @@ +/* { dg-options "-isystem ${srcdir}" } */ + +/* Test that permerrors appear in system headers. */ + +/* The dg-* directives in the header file are ignored. No warnings are + expected. */ +#include + +/* These errors come from permerror-default.c. No errors yet. */