r234528 - [Sema] Diagnose references to unbound arrays in function definitions

David Majnemer david.majnemer at gmail.com
Thu Apr 9 12:53:25 PDT 2015


Author: majnemer
Date: Thu Apr  9 14:53:25 2015
New Revision: 234528

URL: http://llvm.org/viewvc/llvm-project?rev=234528&view=rev
Log:
[Sema] Diagnose references to unbound arrays in function definitions

A [*] is only allowed in a declaration for a function, not in its
definition.  We didn't correctly recurse on reference types while
looking for it, causing us to crash in CodeGen instead of rejecting it.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/vla.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=234528&r1=234527&r2=234528&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Apr  9 14:53:25 2015
@@ -7713,6 +7713,10 @@ static void diagnoseArrayStarInParamType
     diagnoseArrayStarInParamType(S, PointerTy->getPointeeType(), Loc);
     return;
   }
+  if (const auto *ReferenceTy = dyn_cast<ReferenceType>(PType)) {
+    diagnoseArrayStarInParamType(S, ReferenceTy->getPointeeType(), Loc);
+    return;
+  }
   if (const auto *ParenTy = dyn_cast<ParenType>(PType)) {
     diagnoseArrayStarInParamType(S, ParenTy->getInnerType(), Loc);
     return;

Modified: cfe/trunk/test/SemaCXX/vla.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vla.cpp?rev=234528&r1=234527&r2=234528&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vla.cpp (original)
+++ cfe/trunk/test/SemaCXX/vla.cpp Thu Apr  9 14:53:25 2015
@@ -17,3 +17,6 @@ namespace PR18581 {
     incomplete c[n]; // expected-error {{incomplete}}
   }
 }
+
+void pr23151(int (&)[*]) { // expected-error {{variable length array must be bound in function definition}}
+}





More information about the cfe-commits mailing list