From patchwork Sat Nov 18 21:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 166651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1371239vqn; Sat, 18 Nov 2023 13:13:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTdOElp24fBT4Q1l4yyDWVc1c9aWrIiHBi27TAAhLRCEqaXYrkpt7JBPjlyuuPlMI+li/N X-Received: by 2002:a05:6102:1:b0:462:99ec:8f50 with SMTP id j1-20020a056102000100b0046299ec8f50mr606901vsp.32.1700342025724; Sat, 18 Nov 2023 13:13:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700342025; cv=pass; d=google.com; s=arc-20160816; b=WDFJ3mtbDfRqVyWNpu35q8uDbih3BEfBtKlppol87vUnqwlSECHqWq1K8z2cMKbok1 gVF05UBvc2GouERHauo7TkK/LPIS2gBKiVvjcRzDoKlZNqsDYTyeJdg5qHHlIM9Ubyxa S7ufQ7vspnL2E6vghwLuCVCB0uCQR7/PFBBzwqeqCvvYKPKWzV7LSeRsVRSw0bxYlA+K tchzzqnjQrlde2z6v2pRxf7G9VGkkJtdH8eu6MIKPRJ5V9sUA48PsXBbNFq9J8PazBLe wFAJVw8hrkH3yWVXwIqceshKPqClR8ciQb7HDBl8qRAbSMNqoyz4my/rTocgVY1DTli2 p4pg== 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:arc-filter:dmarc-filter:delivered-to; bh=7T2SdvGmU7KwiTEegO5LzANHBgBx1jX5wQdcn4aD3Vc=; fh=k5BQ3iYuwFTza1Z/H+kMrb8l2Z70j0hdnX84UNatFtM=; b=HoLDnNsNseyouGozhf7H2GhxTX9oUT+QdoSJLPc6iKqyU7MmFKiy0Bj733g/KO8v/O pKls5wUqdqw1Y2O+IeLtMEoq3dJddZljxwTcvojQ/5VKGd9kewG5Dz5sYfNEgXMMbCkF 6MeFzC1JFhRrKa1g7pIO7J0585pR7N8DYZiusG3pN1gFo+1uNtUXV5Uo3ckPPhxNE0QJ RwPKuuB1jXEYDCF7kKpxFykLB7+ljmmzpw3TyJ7Abp/J+OgGoAhJCysNmkjjOBot6B21 iNSTRZN9mVRytowwGdPZ6gbxcIdo2pUkiiQwXaDEXM06W90/WeRU+k52wIXLqutX9xVt +aYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tugraz.at header.s=mailrelay header.b=K9ojpSWR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eu19-20020ad44f53000000b0066d07d8ecc3si4084814qvb.610.2023.11.18.13.13.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 13:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@tugraz.at header.s=mailrelay header.b=K9ojpSWR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 776203858C56 for ; Sat, 18 Nov 2023 21:13:45 +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 B98363858C60 for ; Sat, 18 Nov 2023 21:13:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B98363858C60 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 B98363858C60 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=1700342003; cv=none; b=P5HUTDGRVra0KU3aufhNgRcsHtDovTSQ1Bp0GKpOAHx7N573Mo1ma03V3eBk81hA4T+tbWw0VH7Ifssxy8eJ4tpL4z2I8rVpEbdJ9flMsHjOlt7L0SaHbaNw2iZpCrNMSJIzRUVzHM0X+bAWtyAP7muu9wMuNVgT+RaUlmb42I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700342003; c=relaxed/simple; bh=3MBbx9B5AcK76lhodtxmLi4PNBL9s7YY2Nmks2eEgJk=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=lI46OWsbdcVl1bQVW3qRj3Jc/eQl2oJbehYzyG5PhPYyFGIUDLwfOJGz1b6+9HJVN/fD1Cpg4kX7pbkuVyVbEjpiGWD69hFrVo1oyRJ4kpx4aZq8Oppgrq8cIHbT1AgteEZewL7gdYqrL7ZtzI7o56lPZ5hL/Ci7jLNITW1Io48= 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 4SXmhJ14ztz3wdR; Sat, 18 Nov 2023 22:13:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1700341984; bh=7T2SdvGmU7KwiTEegO5LzANHBgBx1jX5wQdcn4aD3Vc=; h=Subject:From:To:Cc:Date; b=K9ojpSWRMhk0uQMEVwJ3eSjzMHrTLxBqAdXhcvpzUOUr/e3hl9o+AKG05Pjt0c+X2 RvsmW70W3BAB4DDhHyfUNzT/bPxshAeXR7YVfT5DD4VDDZw009RGj/UoyN7JoLm29Q R327zbKTAad5mmqpuD3dn8eUhHJCm2GSWrrbRvVQ= Message-ID: <2ef9124eecefe8f39eab9557e5ce76f42e8d6c7c.camel@tugraz.at> Subject: [PATCH 2/4] c: runtime checking for assigment of VM types 2/4 From: Martin Uecker To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Sat, 18 Nov 2023 22:13:03 +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.116 X-Spam-Status: No, score=-10.8 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: 1782937839518327809 X-GMAIL-MSGID: 1782937839518327809 Support instrumentation of function arguments for functions called via a declaration. We can support only simple size expressions without side effects, because the run-time instrumentation is done before the call, but the expressions are evaluated in the callee. gcc/c: * c-typeck.cc (process_vm_constraints): Add support for instrumenting function arguments. (convert_arguments): Instrument function arguments. (convert_for_assigmnent): Adapt. gcc/testsuide/gcc.dg: * vla-bounds-func-1.c: Update. * vla-bounds-func-2.c: New test. * vla-bounds-func-3.c: New test. * vla-bounds-func-4.c: New test. * vla-bounds-func-5.c: New test. * vla-bounds-func-6.c: New test. * vla-bounds-func-7.c: New test. * vla-bounds-func-8.c: New test. * vla-bounds-func-9.c: New test. * vla-bounds-func-10.c: New test. * vla-bounds-func-11.c: New test. * vla-bounds-func-12.c: New test. * vla-bounds-func-13.c: New test. * vla-bounds-func-14.c: New test. * vla-bounds-func-15.c: New test. * vla-bounds-func-16.c: New test. * vla-bounds-func-17.c: New test. * vla-bounds-func-18.c: New test. * vla-bounds-func-19.c: New test. * vla-bounds-func-20.c: New test. --- gcc/c/c-typeck.cc | 151 +++++++++++++++++++--- gcc/testsuite/gcc.dg/vla-bounds-func-1.c | 4 +- gcc/testsuite/gcc.dg/vla-bounds-func-10.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-11.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-12.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-13.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-14.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-15.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-16.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-17.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-18.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-19.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-2.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-20.c | 45 +++++++ gcc/testsuite/gcc.dg/vla-bounds-func-3.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-4.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-5.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-6.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-7.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-8.c | 99 ++++++++++++++ gcc/testsuite/gcc.dg/vla-bounds-func-9.c | 99 ++++++++++++++ 21 files changed, 1641 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-10.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-11.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-12.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-13.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-14.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-15.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-16.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-17.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-18.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-19.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-2.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-20.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-3.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-4.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-5.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-6.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-7.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-8.c create mode 100644 gcc/testsuite/gcc.dg/vla-bounds-func-9.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index cb5887b6255..b65fc450940 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1067,19 +1067,13 @@ common_type (tree t1, tree t2) /* Instrument assignment of variably modified types. */ static tree -c_instrument_vm_assign (location_t loc, tree a, tree b) +c_instrument_vm_assign (location_t loc, tree a, tree b, tree as, tree bs) { gcc_assert (flag_vla_bounds); gcc_assert (TREE_CODE (a) == ARRAY_TYPE); gcc_assert (TREE_CODE (b) == ARRAY_TYPE); - tree as = TYPE_MAX_VALUE (TYPE_DOMAIN (a)); - tree bs = TYPE_MAX_VALUE (TYPE_DOMAIN (b)); - - as = fold_build2 (PLUS_EXPR, sizetype, as, size_one_node); - bs = fold_build2 (PLUS_EXPR, sizetype, bs, size_one_node); - tree t = build2 (NE_EXPR, boolean_type_node, as, bs); tree tt = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0); @@ -3286,7 +3280,8 @@ static tree convert_argument (location_t ploc, tree function, tree fundecl, tree type, tree origtype, tree val, tree valtype, bool npc, tree rname, int parmnum, int argnum, - bool excess_precision, int warnopt) + bool excess_precision, int warnopt, + struct instrument_data **instr_vec) { /* Formal parm type is specified by a function prototype. */ @@ -3446,7 +3441,7 @@ convert_argument (location_t ploc, tree function, tree fundecl, val, origtype, ic_argpass, npc, fundecl, function, parmnum + 1, warnopt, - NULL); + instr_vec); if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0) && INTEGRAL_TYPE_P (type) @@ -3459,15 +3454,110 @@ convert_argument (location_t ploc, tree function, tree fundecl, /* Process all constraints for variably-modified types. */ -static tree +tree process_vm_constraints (location_t location, - struct instrument_data **instr_vec) + struct instrument_data **instr_vec, + tree function, tree fundecl, vec *values) { tree instr_expr = void_node; + tree args = NULL; + + /* Find the arguments for the function declaration / type. */ + if (function) + { + if (FUNCTION_DECL == TREE_CODE (function)) + { + fundecl = function; + args = DECL_ARGUMENTS (fundecl); + } + else + { + /* Functions called via pointers are not yet supported. */ + return void_node; + } + } for (struct instrument_data* d = *instr_vec; d; d = d->next) { - tree in = c_instrument_vm_assign (location, d->t1, d->t2); + tree t1 = d->t1; + tree t2 = d->t2; + + gcc_assert (ARRAY_TYPE == TREE_CODE (t1)); + gcc_assert (ARRAY_TYPE == TREE_CODE (t2)); + + tree as = TYPE_MAX_VALUE (TYPE_DOMAIN (t1)); + tree bs = TYPE_MAX_VALUE (TYPE_DOMAIN (t2)); + + gcc_assert (as); + gcc_assert (bs); + + as = fold_build2 (PLUS_EXPR, sizetype, as, size_one_node); + bs = fold_build2 (PLUS_EXPR, sizetype, bs, size_one_node); + + if (function) + { + + if (INTEGER_CST == TREE_CODE (bs)) + goto cont; + + if (NOP_EXPR == TREE_CODE (bs) + && SAVE_EXPR == TREE_CODE (TREE_OPERAND (bs, 0))) + { + tree bs1 = TREE_OPERAND (bs, 0); + tree bs2 = TREE_OPERAND (bs1, 0); + + /* Another parameter of the current functions. */ + if (PARM_DECL == TREE_CODE (bs2) + && (DECL_CONTEXT (bs2) == fundecl + || DECL_CONTEXT (bs2) == NULL)) + { + tree arg = args; + int pos = 0; + while (arg) + { + if (arg == bs2) + { + bs = (*values)[pos]; + bs = save_expr (bs); + bs = build1 (NOP_EXPR, sizetype, bs); + break; + } + pos++; + arg = DECL_CHAIN (arg); + } + if (!arg) + goto giveup; + goto cont; + } + + /* A parameter of an enclosing function. */ + if (PARM_DECL == TREE_CODE (bs2) + && DECL_CONTEXT (bs2) != fundecl) + { + bs2 = unshare_expr (bs2); + bs1 = save_expr (bs2); + bs = build1 (NOP_EXPR, sizetype, bs1); + goto cont; + } + + /* A variable with enclosing scope. */ + if (VAR_DECL == TREE_CODE (bs2)) + { + bs2 = unshare_expr (bs2); + bs1 = save_expr (bs2); + bs = build1 (NOP_EXPR, sizetype, bs1); + goto cont; + } + } + giveup: + /* Give up. If we do not understand a size expression, we can + also not instrument any of the others because it may have + side effects affecting them. (We could restart and instrument + only the ones with integer constants.) */ + return void_node; + } +cont: + tree in = c_instrument_vm_assign (location, t1, t2, as, bs); instr_expr = fold_build2 (COMPOUND_EXPR, void_type_node, in, instr_expr); } return instr_expr; @@ -3578,6 +3668,12 @@ convert_arguments (location_t loc, vec arg_loc, tree typelist, } } + struct instrument_data *instr_first = NULL; + struct instrument_data **instr_vec = NULL; + + if (flag_vla_bounds) + instr_vec = &instr_first; + /* Scan the given expressions (VALUES) and types (TYPELIST), producing individual converted arguments. */ @@ -3690,7 +3786,7 @@ convert_arguments (location_t loc, vec arg_loc, tree typelist, tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum]; parmval = convert_argument (ploc, function, fundecl, type, origtype, val, valtype, npc, rname, parmnum, argnum, - excess_precision, 0); + excess_precision, 0, instr_vec); } else if (promote_float_arg) { @@ -3745,7 +3841,7 @@ convert_arguments (location_t loc, vec arg_loc, tree typelist, convert_argument (ploc, function, fundecl, builtin_type, origtype, val, valtype, npc, rname, parmnum, argnum, excess_precision, - OPT_Wbuiltin_declaration_mismatch); + OPT_Wbuiltin_declaration_mismatch, NULL); } if (typetail) @@ -3757,6 +3853,31 @@ convert_arguments (location_t loc, vec arg_loc, tree typelist, gcc_assert (parmnum == vec_safe_length (values)); + if (instr_vec) + { + if (0 < parmnum && instr_vec && instr_first != NULL) + { + tree instr_expr = process_vm_constraints (loc, instr_vec, function, fundecl, values); + /* We have to make sure that all parameters are evaluated first, + because we may use size expressions in it to check bounds. */ + if (void_node != instr_expr) + { + tree parmval = (*values)[0]; + parmval = save_expr (parmval); + instr_expr = fold_build2 (COMPOUND_EXPR, void_type_node, parmval, instr_expr); + parmval = fold_build2 (COMPOUND_EXPR, TREE_TYPE (parmval), instr_expr, parmval); + (*values)[0] = parmval; + } + } + while (instr_first) + { + struct instrument_data *next = instr_first->next; + free (instr_first); + instr_first = next; + } + instr_vec = NULL; + } + if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node) { error_at (loc, "too few arguments to function %qE", function); @@ -6850,7 +6971,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, { /* We have to make sure that the rhs is evaluated first, because we may use size expressions in it to check bounds. */ - tree instr_expr = process_vm_constraints (location, instr_vec); + tree instr_expr = process_vm_constraints (location, instr_vec, NULL, NULL, NULL); if (void_node != instr_expr) { ret = save_expr (ret); diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-1.c b/gcc/testsuite/gcc.dg/vla-bounds-func-1.c index e4856017419..dd5f3e76b50 100644 --- a/gcc/testsuite/gcc.dg/vla-bounds-func-1.c +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fcheck-vla-bounds" } */ +/* { dg-options "-fvla-bounds" } */ // make sure we do not ICE on any of these @@ -51,6 +51,6 @@ int c(int u, char (*a)[u]) { } int d(void) { char a[3]; - c(3, &a); + c(3, &a); /* "Function call not instrumented." */ } diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-10.c b/gcc/testsuite/gcc.dg/vla-bounds-func-10.c new file mode 100644 index 00000000000..19942d2de95 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-10.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-11.c b/gcc/testsuite/gcc.dg/vla-bounds-func-11.c new file mode 100644 index 00000000000..42859b0bd14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-11.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +TRY( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-12.c b/gcc/testsuite/gcc.dg/vla-bounds-func-12.c new file mode 100644 index 00000000000..94334792b62 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-12.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + d1(3, &C0); +TRY( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-13.c b/gcc/testsuite/gcc.dg/vla-bounds-func-13.c new file mode 100644 index 00000000000..95c47e9587d --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-13.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +TRY( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-14.c b/gcc/testsuite/gcc.dg/vla-bounds-func-14.c new file mode 100644 index 00000000000..8ac1262e222 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-14.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-15.c b/gcc/testsuite/gcc.dg/vla-bounds-func-15.c new file mode 100644 index 00000000000..ef59f6cad4b --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-15.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +TRY( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-16.c b/gcc/testsuite/gcc.dg/vla-bounds-func-16.c new file mode 100644 index 00000000000..710871e6db1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-16.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +TRY( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-17.c b/gcc/testsuite/gcc.dg/vla-bounds-func-17.c new file mode 100644 index 00000000000..f2522030831 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-17.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +TRY( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-18.c b/gcc/testsuite/gcc.dg/vla-bounds-func-18.c new file mode 100644 index 00000000000..779dd370c8f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-18.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +TRY( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-19.c b/gcc/testsuite/gcc.dg/vla-bounds-func-19.c new file mode 100644 index 00000000000..7a129d2851f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-19.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +TRY( b4(&A0); ) // 4 != 3 + +ERROR( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-2.c b/gcc/testsuite/gcc.dg/vla-bounds-func-2.c new file mode 100644 index 00000000000..19942d2de95 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-2.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-20.c b/gcc/testsuite/gcc.dg/vla-bounds-func-20.c new file mode 100644 index 00000000000..8532a2f3223 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-20.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + + + +void b0(int n, char (*a)[n]) { } +void b1(int m, char (*a)[m]); +void b2(int m; char (*a)[m], int m) { } +void b3(int m; char (*a)[m], int m); +int n; +void b4(char (*a)[n]) { } +void b5(char (*a)[n]); + +int main() +{ + signal(SIGILL, handler); + + char A0[3]; +ERROR( b1(4, &A0); ) // 4 != 3 +ERROR( b0(4, &A0); ) // 4 != 3 + +ERROR( b2(&A0, 4); ) // 4 != 3 + +ERROR( b3(&A0, 4); ) // 4 != 3 + + n = 4; +ERROR( b4(&A0); ) // 4 != 3 + +TRY( b5(&A0); ) // 4 != 3 +} + + +void b1(int n, char (*a)[n]) { } +void b3(int m; char (*a)[m], int m) { } +void b5(char (*a)[n]) { } + + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-3.c b/gcc/testsuite/gcc.dg/vla-bounds-func-3.c new file mode 100644 index 00000000000..d21337f1de0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-3.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-O1 -fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +TRY( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-4.c b/gcc/testsuite/gcc.dg/vla-bounds-func-4.c new file mode 100644 index 00000000000..14a0efae913 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-4.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +TRY( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* "incompatible pointer type" */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-5.c b/gcc/testsuite/gcc.dg/vla-bounds-func-5.c new file mode 100644 index 00000000000..57f641695a0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-5.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +TRY( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-6.c b/gcc/testsuite/gcc.dg/vla-bounds-func-6.c new file mode 100644 index 00000000000..88986a8bf23 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-6.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +TRY( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-7.c b/gcc/testsuite/gcc.dg/vla-bounds-func-7.c new file mode 100644 index 00000000000..788d3243c58 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-7.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +TRY( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-8.c b/gcc/testsuite/gcc.dg/vla-bounds-func-8.c new file mode 100644 index 00000000000..c0cbf85b647 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-8.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +TRY( c0(&D2); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} + diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-9.c b/gcc/testsuite/gcc.dg/vla-bounds-func-9.c new file mode 100644 index 00000000000..3e65106f053 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vla-bounds-func-9.c @@ -0,0 +1,99 @@ +/* { dg-do run } */ +/* { dg-options "-fvla-bounds" } */ + +#include +#include + +static void handler(int) { exit(0); } + +#define TRY(...) __VA_ARGS__ __builtin_abort(); +#define ERROR(...) if (0) { __VA_ARGS__ } + +int m, n; + +static void a0(char (*a)[4]) { } +static void b0(char (*a)[n]) { } +static void c0(char (*a)[n][m]) { } +static void d0(char (*a)[4][m]) { } +static void e0(char (*a)[n][3]) { } +static void f0(char a[n][m]) { } + +static void b1(int u, char (*a)[u]) { } +static void c1(int u, int v, char (*a)[u][v]) { } +static void d1(int v, char (*a)[4][v]) { } +static void e1(int u, char (*a)[u][3]) { } +static void f1(int u, int v, char a[u][v]) { } + + + +int main() +{ + signal(SIGILL, handler); + + m = 3, n = 4; + + int u = 4; + int v = 3; + + /* function arguments */ + + char A0[4]; + char A1[u]; + char B0[3]; + char B1[v]; + + a0(&A0); + a0(&A1); + a0(&B0); /* { dg-warning "incompatible pointer type" } */ +ERROR( a0(&B1); ) // 4 != 3 + + b0(&A0); + b0(&A1); +ERROR( b0(&B0); ) // 4 != 3 + +ERROR( b0(&B1); ) // 4 != 3 + + b1(4, &A0); +ERROR( b1(4, &B0); ) // 4 != 3 + + char C0[4][3]; + char C1[u][3]; + char C2[4][v]; + char C3[u][v]; + char D0[3][4]; + char D1[v][4]; + char D2[3][u]; + char D3[v][u]; + + c0(&C0); + c0(&C1); + c0(&C2); + c0(&C3); +ERROR( c0(&D0); ) // 4 != 4, 3 != 4 + +ERROR( c0(&D1); ) // 4 != 3, 3 != 4 + +ERROR( c0(&D2); ) // 4 != 3, 3 != 4 + +TRY( c0(&D3); ) // 4 != 3, 3 != 4 + + d0(&C0); +ERROR( d0(&D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + d1(3, &C0); +ERROR( d1(3, &D0); ) /* { dg-warning "incompatible pointer type" } */ + // 3 != 4 + + e0(&C0); + e0(&D0); /* { dg-warning "incompatible pointer type" } */ + e1(4, &C0); + e1(4, &D0); /* { dg-warning "incompatible pointer type" } */ + + f0(C0); +ERROR( f0(D0); ) // 3 != 4 + + f1(4, 3, C0); + f1(4, 3, D0); // 3 != 4 +} +