Add warning for the case when a function call can not be instrumented
and add documentation for instrumentation of function calls.

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 | 17 ++++++++++++++---
 gcc/testsuite/gcc.dg/vla-bounds-func-1.c | 6 +++---
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 786cd4ce52a..7070ff767bf 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1542,6 +1542,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 6ffa0c24e0c..3f380761efd 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -3967,6 +3967,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;
 }
 }
@@ -4050,6 +4052,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 8d6d68e4f27..510d29735a7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10699,6 +10699,13 @@ void g (int n)
 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
+@option{-fvla-bounds} to detect inconsistencies between the bounds of
+VLA parameters at runtime.
+
+
 @opindex Wvolatile-register-var
 @opindex Wno-volatile-register-var
 @item -Wvolatile-register-var
@@ -20836,9 +20843,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 36072a372a3..b7a994a80b7 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
@@ -30,7 +30,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 */
@@ -50,5 +50,5 @@ 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." } */
 }
-- 
2.39.2



Reply via email to