[4/4] c: runtime checking for assigment of VM types 4/4

Message ID ec98368eda9967482368e0bdf0cfb7ed7790c3c3.camel@tugraz.at
State Unresolved
Headers
Series [1/4] c: runtime checking for assigment of VM types 1/4 |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Martin Uecker Nov. 18, 2023, 9:14 p.m. UTC
  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(-)
  

Patch

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." } */
 }