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: 80233 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFD653858C2B for ; Sat, 18 Nov 2023 21:14:42 +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+patchwork=sourceware.org@gcc.gnu.org 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." } */ }