From patchwork Sat Nov 18 21:14:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 166653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1371559vqn; Sat, 18 Nov 2023 13:14:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFe3LFzNfHYDPvhMlkcrYVN2afphQ0VafuxHfL+6SJXpdrB+QjI9FdURhPfKRJ3aAmaIQj0 X-Received: by 2002:a05:6358:4407:b0:168:d2f8:d2ad with SMTP id z7-20020a056358440700b00168d2f8d2admr3206282rwc.7.1700342090482; Sat, 18 Nov 2023 13:14:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700342090; cv=pass; d=google.com; s=arc-20160816; b=DfrKy+IVWzkIO+tshqHSfdG5jSnD0i9z060heMcxE3dzokN4NLPmPH6u8h+DouzRnI hWtFg0xHcCrUZktLeVppb0iuLAOWXd5NIva+DTKhV67gAiBm0lzFv8uBQcy0g3sRhGXu NA+vMqErVADMLvfHY1siOcFYdh+tbeOsnBd+kh5/FsxzyOWB0+399zZ/hTHn9a4Har7D 06as4IRnfvffza1uGa67E8g2wfIfZ9Ob8fBJbsr0BVWQOrgxZLsUTO2mKR2K4xSBDvns 42BSgdv3cMKLBSv3sk4I/AERXQFlT8Vi9ttSjIllJmpS2cs6l9s+RuOqawSQDRmvzCZD eWMg== 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=G0IojL0fpC/kExPhm81rMe7jx6zKHbXhp4kPPCn6zw0=; fh=k5BQ3iYuwFTza1Z/H+kMrb8l2Z70j0hdnX84UNatFtM=; b=G+bTjgjiMlgrdcwmiC3Wd3L/wkxLOE8MRacEYZ2/vGwxMuuY3vc7lP/kj3TPHVhcWy t186eY9s2I6p42cRw53LbK9uEyr7CxY1eesbnJi4RVtY5ajc39aZzzPBHKU25248s5LG y25HtHAQLWhTisP1Ou64T3csqR1CyKvxBVhwgwGPdMHI0beiMOr2NkNCcTAWlzEB6JFC 2C3OcRduvki9+ph6mOqRtUsu4rDxsNLjOp9vpY8lBcnaeQGkwyTzqLAuU2wta2K6ZqZc UoK7IHJwVxAmlvLgAvC25H5E78qd7DoiVtOR4+8G6SNVoMmDVyxJ4t1MmqvnQD13d1ta Jm3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tugraz.at header.s=mailrelay header.b=GNQpsMxZ; 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 v2-20020a05622a014200b0041b940923d7si4410864qtw.261.2023.11.18.13.14.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 13:14:50 -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=GNQpsMxZ; 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 400B73858419 for ; Sat, 18 Nov 2023 21:14:50 +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 2EF673858C74 for ; Sat, 18 Nov 2023 21:14:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EF673858C74 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 2EF673858C74 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=1700342061; cv=none; b=mPgqKWkTHytQJpiN8BmvXnMxL2csBJbUjndQu2bIuxCop2dKGzQylcwi9DxZQkXx4JJu9p50rynHT+h9WiDCvLZDwTSroBaBtInhj2ogMSEUlDj8U5PqTbAtT7i+n8Lb+eekEuzRtPkzihXnwkHMkeMDO+7uL40ImWaLZP9Z4nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700342061; c=relaxed/simple; bh=IxIIEL/1GXisg0wH2wwzxpvCOR5TMYfn1ZW+DnwPJxM=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=FXz0/twM/pHTIn5giZ2Zx9QKHz4UbwxjlNfTB+kePGD6kucHl9OmCo8mQUQg59c2IUkXLArqfxdPnjHikCOYCL9LOdMdYwwr14vBe2MfN7zQ1KdKVu3eZkz541Havyn+szpTwGngGDRY0vUg2D4rzkTjNp0XmYkZjWU/PSZS11Q= 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 4SXmjj5ZRjz1LLyX; Sat, 18 Nov 2023 22:14:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4SXmjj5ZRjz1LLyX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1700342057; bh=G0IojL0fpC/kExPhm81rMe7jx6zKHbXhp4kPPCn6zw0=; h=Subject:From:To:Cc:Date:From; b=GNQpsMxZ2gkuaVg+dqgc3lY5wG51paLpcyzGt1pNfwQYuM1GJhzMWE90BZhGAHFH8 p53rmeSqKc7lLYznoI4rMwFMpBQWJkjy3jCX34k8D+xeSXTJ0omE4/jT0Xb9VZ3uPM 59bTDG7+efw3i60evfoRyFDzRNDMmvG9mGrigcZg= Message-ID: Subject: [PATCH 4/4] c: runtime checking for assigment of VM types 4/4 From: Martin Uecker To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Sat, 18 Nov 2023 22:14:17 +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=-11.0 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: 1782937907892517923 X-GMAIL-MSGID: 1782937907892517923 Add warning for the case when a function call can not be instrumened. gcc/c-family/: * c.opt (Wvla-parameter-missing-check): Add warning. gcc/c/: * c-typeck.cc (process_vm_constraints): Add warning. gcc/doc/: * invoke.texi (Wvla-parameter-missing-check): Document warning. (flag_vla_bounds): Update. gcc/testsuite/: * gcc.dg/vla-bounds-func-1.c: Add warning. --- gcc/c-family/c.opt | 5 +++++ gcc/c/c-typeck.cc | 4 ++++ gcc/doc/invoke.texi | 11 ++++++++--- gcc/testsuite/gcc.dg/vla-bounds-func-1.c | 6 +++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 29bc0956181..bd45ba577bd 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1485,6 +1485,11 @@ Wvla-parameter C ObjC C++ ObjC++ Var(warn_vla_parameter) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn about mismatched declarations of VLA parameters. +Wvla-parameter-missing-check +C ObjC Var(warn_vla_parameter_check) Warning Init(0) +When using run-time checking of VLA bounds, warn about function calls which +could not be instrumented. + Wvolatile C++ ObjC++ Var(warn_volatile) Warning Warn about deprecated uses of volatile qualifier. diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 1200abc2f4a..a4fb0a6b527 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -3481,6 +3481,8 @@ process_vm_constraints (location_t location, { /* FIXME: this can happen when forming composite types for the conditional operator. */ + warning_at (location, OPT_Wvla_parameter_missing_check, + "Function call not instrumented"); return void_node; } } @@ -3564,6 +3566,8 @@ process_vm_constraints (location_t location, 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.) */ + warning_at (location, OPT_Wvla_parameter_missing_check, + "Function call not instrumented"); return void_node; } cont: diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c94ca59086b..6f4bbd43919 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -10269,6 +10269,7 @@ void g (int n) @option{-Warray-parameter} option triggers warnings for similar problems involving ordinary array arguments. + @opindex Wvla-parameter-missing-check @item -Wvla-parameter-missing-check Warn when function calls can not be instrumented with the use of @@ -20063,9 +20064,13 @@ The @var{string} should be different for every file you compile. @item -fvla-bounds This option is only available when compiling C code. If activated, additional code is emitted that verifies at run time for assignments -involving variably-modified types that corresponding size expressions -evaluate to the same value. - +and function calls involving variably-modified types that corresponding +size expressions evaluate to the same value. Note that for function +calls the visible declarations needs to have a size expression that +matches the size expression in the definition. A mismatch seen by the +the compiler is diagnosed by @option{-Wvla-parameter}). In same cases, +a function call can not be instrumented. This can be diagnosed by +@option{-Wvla-parameter-missing-check}. @opindex save-temps @item -save-temps diff --git a/gcc/testsuite/gcc.dg/vla-bounds-func-1.c b/gcc/testsuite/gcc.dg/vla-bounds-func-1.c index 72dba39107b..205e5174185 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 "-fvla-bounds" } */ +/* { dg-options "-fvla-bounds -Wvla-parameter-missing-check" } */ // make sure we do not ICE on any of these @@ -31,7 +31,7 @@ void f(void) int u = 3; int v = 4; char a[u][v]; - (1 ? f1 : f2)(u, v, a); /* "Function call not instrumented." */ + (1 ? f1 : f2)(u, v, a); /* { dg-warning "Function call" "not instrumented." } */ } /* size expression in parameter */ @@ -51,6 +51,6 @@ int c(int u, char (*a)[u]) { } int d(void) { char a[3]; - c(3, &a); /* "Function call not instrumented." */ + c(3, &a); /* { dg-warning "Function call" "not instrumented." } */ }