From patchwork Sat Nov 18 21:13:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 166652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1371396vqn; Sat, 18 Nov 2023 13:14:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhU65CURXWczsakKIEFEh4lWDeuY589Z3loA+CVbXrLjJhc+RFUGsPiYJmkqqs3iKlUZMr X-Received: by 2002:a05:6214:1241:b0:672:6df3:e75e with SMTP id r1-20020a056214124100b006726df3e75emr3598248qvv.64.1700342060202; Sat, 18 Nov 2023 13:14:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700342060; cv=pass; d=google.com; s=arc-20160816; b=yPG+E+1u6/NBK057UENUtMZJXyiINmRwpq7I7ZRG+IVEmj8uGxDhPpPChLqQcf3uo4 EtauUsWTuyehFwBZr41JZqJlJxsnXF6oi1bl1KlHM/EqN6J+8hGYqHdrJzuj/e/aRH5r 7v39b+eK7kIrl9/QZCVbJBkFXU+ocQkYlXFb53HsRU0RN5PGx94cHVJzLxERcBYLzYpx uL9WTUFkMWRFqZYBBuC7oNooN6V86xd3GYxVyc9p0fO6ArB7yjW0eXUkbUQNBxRWvXLL TRGJAJTV/Dpo4+POi57OA7d/edoxwlE5Pkw1JNRO+oOwlqUoqsYbORq1kL3NgR/jtYHC TvoQ== 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 :content-transfer-encoding:date:cc:to:from:subject:message-id :dkim-signature:dkim-filter:arc-filter:dmarc-filter:delivered-to; bh=Y+VmK9KpOL0zhGKpLt+TzqXq9+vurPIxW3bRFgc/5SY=; fh=k5BQ3iYuwFTza1Z/H+kMrb8l2Z70j0hdnX84UNatFtM=; b=gCDa7EGSs4fWfPyvht+EwhRG9RROmZPGDDrRXDPusrV2QOo31I9RuWTgwiO8FNyVTk 2ZTJMzu+P/v65/IMPkNFckthan4xsBcBYK6LgDJRYrROdR08mESI4abPvEAr6hHIBPTw yXBCZrK5+M2ISnScVUx32AecY/qXMMfXzTXBj6ttfeeJF2/edIsIYOJWrrWnPTkPtSJN 2HMDJ/EMCJ2DJkmjejj+XW00Q1+R5wN4B27OFRambeLoTCQKWPi9aQ6UUafj6e7Ma4P5 082sRcAgifs0U/TDxLsTFuFk1D5OfdSRM1onF5tuwzmf6/+LuwNO2KF8v3GYQkB32X5o 0Xdw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tugraz.at header.s=mailrelay header.b=frEoX1oZ; 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=QUARANTINE sp=NONE dis=NONE) header.from=tugraz.at Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ne16-20020a056214425000b0065af55afb2bsi4258288qvb.469.2023.11.18.13.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 13:14:20 -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=@tugraz.at header.s=mailrelay header.b=frEoX1oZ; 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=QUARANTINE sp=NONE dis=NONE) header.from=tugraz.at Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF8323858C30 for ; Sat, 18 Nov 2023 21:14:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id 89B0C3858421 for ; Sat, 18 Nov 2023 21:13:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89B0C3858421 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 89B0C3858421 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.27.2.202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700342037; cv=none; b=Y2wzucoP4feunERuqrAfkgnAEjRh/o+l+xWwtoDiJxmXOFofxc/m2ghBkDP2/l/n+WfHa/uafluIrU6FZYY24RISMIDuZ1+vaEJEYhW9grfDzrf5Ky8t+Z0g1HNGCyaUBtOfogsrNr1l6b2Zsx4slSTT6BZTmgUd0oz07e/Dmzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700342037; c=relaxed/simple; bh=mdcW2Ar9xke+du3d6ps/+DhiCNs5TkR+jtl/kWzfnBw=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=GPHL1F67nHp7IdI+KdcJ8uTGnfvKAwBop5aPiTjs+zUZVEpqFAxeehhyDlV4MaQ9hbHxLEl7rlABW0LdyXakNFqyg8mW1Wh1DjPOA/iHDxNpjgy0vOxiAd5EDXxyiC8Vnw6ZkkEqY194IYdJB7CkivQ5NvKQU4dVCHWJnZ8KDlk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from vra-173-60.tugraz.at (vra-173-60.tugraz.at [129.27.173.60]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4SXmj45JLBz1LLyX; Sat, 18 Nov 2023 22:13:44 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4SXmj45JLBz1LLyX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1700342025; bh=Y+VmK9KpOL0zhGKpLt+TzqXq9+vurPIxW3bRFgc/5SY=; h=Subject:From:To:Cc:Date:From; b=frEoX1oZFzITiduCH1zRhprnSZtmSM+vw8qE3eoE+8Btl46Jkw9ND/w6ObUrSqL1n 0eU5l2MT2lju+l9GLEmPNhpBxCgAi8RIsTiqKjXPtK2dj2sGJMeCnr2505hTkhSuHu Mt52Ze/ALDQHbngENtbo9duGqiYTN/HzWmK5safg= Message-ID: <5af943163b8c49f75022e2bae151c18afd4b7c0c.camel@tugraz.at> Subject: [PATCH 3/4] c: runtime checking for assigment of VM types 3/4 From: Martin Uecker To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Sat, 18 Nov 2023 22:13:44 +0100 User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: 1782937876039828894 X-GMAIL-MSGID: 1782937876039828894 Support instrumentation of functions called via pointers. To do so, record the declaration with the parameter types, so that it can be retrieved later. gcc/c: c-decl.cc (get_parm_info): Record function declaration for arguments. c-typeck.cc (process_vm_constraints): Instrument functions called via pointers. gcc/testsuide/gcc.dg: * vla-bounds-func-1.c: Add warning. * vla-bounds-fnptr.c: New test. * vla-bounds-fnptr-1.c: New test. * vla-bounds-fnptr-2.c: New test. * vla-bounds-fnptr-3.c: New test. * vla-bounds-fnptr-4.c: New test. * vla-bounds-fnptr-5.c: New test. --- gcc/c/c-decl.cc | 4 ++ gcc/c/c-typeck.cc | 14 +++- gcc/testsuite/gcc.dg/vla-bounds-fnptr-1.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-fnptr-2.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-fnptr-3.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-fnptr-4.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-fnptr-5.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-fnptr.c | 78 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-1.c | 2 +- 9 files changed, 485 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr-1.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr-2.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr-3.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr-4.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr-5.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-fnptr.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 64d3a941cb9..84a30f7476a 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -8549,6 +8549,10 @@ get_parm_info (bool ellipsis, tree expr) declared types. The back end may override this later. */ DECL_ARG_TYPE (decl) = type; types = tree_cons (0, type, types); + + /* Record the decl for use for VLA bounds checking. */ + if (flag_vla_bounds) + TREE_PURPOSE (types) = decl; } break; diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index b65fc450940..1200abc2f4a 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -3472,9 +3472,19 @@ process_vm_constraints (location_t location, } else { - /* Functions called via pointers are not yet supported. */ - return void_node; + while (FUNCTION_TYPE != TREE_CODE (function)) + function = TREE_TYPE (function); + + args = TREE_PURPOSE (TYPE_ARG_TYPES (function)); + + if (!args) + { + /* FIXME: this can happen when forming composite types for the + conditional operator. */ + return void_node; + } } + gcc_assert (PARM_DECL == TREE_CODE (args)); } for (struct instrument_data* d = *instr_vec; d; d = d->next) diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr-1.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-1.c new file mode 100644 index 00000000000..b9af87f6338 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-1.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +TRY( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +ERROR( (*p)(3, &A0); ) // 4 != 3 +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr-2.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-2.c new file mode 100644 index 00000000000..4ec326af06c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-2.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +TRY( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +ERROR( (*p)(3, &A0); ) // 4 != 3 +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr-3.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-3.c new file mode 100644 index 00000000000..9e28a8e4db7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-3.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +TRY( (*p)(3, &A0); ) // 4 != 3 +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr-4.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-4.c new file mode 100644 index 00000000000..7f70b53cc4c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-4.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +ERROR( (*p)(3, &A0); ) // 4 != 3 +TRY( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr-5.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-5.c new file mode 100644 index 00000000000..012d32ff234 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr-5.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +ERROR( (*p)(3, &A0); ) // 4 != 3 +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +TRY( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-fnptr.c b/gcc/testsuite/gcc.dg/vla-bounds-fnptr.c new file mode 100644 index 00000000000..9d102673c94 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-fnptr.c @@ -0,0 +1,78 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void foo1(void (*p)(int n, char (*a)[n])) +{ + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void b0(int n, char (*a)[n]) { } + + +int n; + +void foo2(void (*p)(int n, char (*a)[n])) +{ + n = 4; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo3(void (*p)(int n0, char (*a)[n])) +{ + n = 4; + char A0[3]; +ERROR( (*p)(3, &A0); ) // 4 != 3 +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + +void foo4(void (*p)(int n, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); +ERROR( (*p)(4, &A0); ) // 4 != 3 +} + + +void foo5(void (*p)(int n0, char (*a)[n])) +{ + n = 3; + char A0[3]; + (*p)(3, &A0); + (*p)(4, &A0); +} + + +void b1(int n0, char (*a)[n]) { } + + + +int main() +{ + signal(SIGILL, handler); + + foo1(&b0); + + foo2(&b1); + foo3(&b1); // we should diagnose mismatch and run-time discrepancies + + foo4(&b1); + foo5(&b1); // we should diagnose mismatch and run-time discrepancies +} + + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-1.c b/gcc/testsuite/gcc.dg/vla-bounds-func-1.c index dd5f3e76b50..72dba39107b 100644 --- a/gcc/testsuite/gcc.dg/vla-bounds-func-1.c +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-1.c @@ -31,7 +31,7 @@ void f(void) int u = 3; int v = 4; char a[u][v]; - (1 ? f1 : f2)(u, v, a); + (1 ? f1 : f2)(u, v, a); /* "Function call not instrumented." */ } /* size expression in parameter */