[4/4] c: runtime checking for assigment of VM types 4/4
Checks
Commit Message
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(-)
@@ -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.
@@ -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:
@@ -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
@@ -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." } */
}