r180732 - c language: diagnose use of "[*]" on any array dimension
Fariborz Jahanian
fjahanian at apple.com
Mon Apr 29 15:01:26 PDT 2013
Author: fjahanian
Date: Mon Apr 29 17:01:25 2013
New Revision: 180732
URL: http://llvm.org/viewvc/llvm-project?rev=180732&view=rev
Log:
c language: diagnose use of "[*]" on any array dimension
in the parameter of a function definition. Currently,
it crashes in irgen if it is on other than the 1st dimension.
// rdar://13705391
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/crash-invalid-array.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=180732&r1=180731&r2=180732&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Apr 29 17:01:25 2013
@@ -5703,12 +5703,14 @@ bool Sema::CheckParmsForFunctionDef(Parm
// notation in their sequences of declarator specifiers to specify
// variable length array types.
QualType PType = Param->getOriginalType();
- if (const ArrayType *AT = Context.getAsArrayType(PType)) {
+ while (const ArrayType *AT = Context.getAsArrayType(PType)) {
if (AT->getSizeModifier() == ArrayType::Star) {
// FIXME: This diagnostic should point the '[*]' if source-location
// information is added for it.
Diag(Param->getLocation(), diag::err_array_star_in_function_definition);
+ break;
}
+ PType= AT->getElementType();
}
}
Modified: cfe/trunk/test/Sema/crash-invalid-array.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/crash-invalid-array.c?rev=180732&r1=180731&r2=180732&view=diff
==============================================================================
--- cfe/trunk/test/Sema/crash-invalid-array.c (original)
+++ cfe/trunk/test/Sema/crash-invalid-array.c Mon Apr 29 17:01:25 2013
@@ -15,3 +15,10 @@ int main()
p[i][i] = i;
}
}
+
+// rdar://13705391
+void foo(int a[*][2]) {(void)a[0][1]; } // expected-error {{variable length array must be bound in function definition}}
+void foo1(int a[2][*]) {(void)a[0][1]; } // expected-error {{variable length array must be bound in function definition}}
+void foo2(int a[*][*]) {(void)a[0][1]; } // expected-error {{variable length array must be bound in function definition}}
+void foo3(int a[2][*][2]) {(void)a[0][1][1]; } // expected-error {{variable length array must be bound in function definition}}
+void foo4(int a[2][*][*]) {(void)a[0][1][1]; } // expected-error {{variable length array must be bound in function definition}}
More information about the cfe-commits
mailing list