]> granicus.if.org Git - clang/commitdiff
c language: diagnose use of "[*]" on any array dimension
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 29 Apr 2013 22:01:25 +0000 (22:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 29 Apr 2013 22:01:25 +0000 (22:01 +0000)
in the parameter of a function definition. Currently,
it crashes in irgen if it is on other than the 1st dimension.
// rdar://13705391

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/crash-invalid-array.c

index 8adfbd598f0ead30468faeacf04add89555ba2e8..c19fe27c7fe4d1807c7f5c0d0cf7adc47607d281 100644 (file)
@@ -5703,12 +5703,14 @@ bool Sema::CheckParmsForFunctionDef(ParmVarDecl **P, ParmVarDecl **PEnd,
     //   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();
     }
   }
 
index a3bc03b70b56cd1d5b49b0916929add1cd8d7ffc..eeac39148ca4de179f348e99e376c0528f58fedc 100644 (file)
@@ -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}}