summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaChecking.cpp14
-rw-r--r--clang/test/Sema/vla.c6
3 files changed, 22 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0d1a0e21024..c4ce6affc6d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,8 @@ def warn_unused_variable : Warning<"unused variable %0">,
InGroup<UnusedVariable>, DefaultIgnore;
def warn_decl_in_param_list : Warning<
"declaration of %0 will not be visible outside of this function">;
+def err_array_star_in_function_definition : Error<
+ "variable length array must be bound in function definition">;
def warn_implicit_function_decl : Warning<
"implicit declaration of function %0">,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1e7641690d9..4e2e9c7376b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2616,6 +2616,20 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
!Param->isImplicit() &&
!getLangOptions().CPlusPlus)
Diag(Param->getLocation(), diag::err_parameter_name_omitted);
+
+ // C99 6.7.5.3p12:
+ // If the function declarator is not part of a definition of that
+ // function, parameters may have incomplete type and may use the [*]
+ // notation in their sequences of declarator specifiers to specify
+ // variable length array types.
+ QualType PType = Param->getOriginalType();
+ if (const ArrayType *AT = Context.getAsArrayType(PType)) {
+ if (AT->getSizeModifier() == ArrayType::Star) {
+ // FIXME: This diagnosic should point the the '[*]' if source-location
+ // information is added for it.
+ Diag(Param->getLocation(), diag::err_array_star_in_function_definition);
+ }
+ }
}
return HasInvalidParm;
diff --git a/clang/test/Sema/vla.c b/clang/test/Sema/vla.c
index 7ddd432fbc0..ebf9b889ee2 100644
--- a/clang/test/Sema/vla.c
+++ b/clang/test/Sema/vla.c
@@ -54,3 +54,9 @@ int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}}
const int f5_ci = 1;
void f5() { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}}
+
+// PR5185
+void pr5185(int a[*]);
+void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}}
+{
+}
OpenPOWER on IntegriCloud