[cfe-commits] r147900 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp test/SemaObjC/property.m test/SemaObjCXX/properties.mm

John McCall rjmccall at apple.com
Tue Jan 10 16:14:46 PST 2012


Author: rjmccall
Date: Tue Jan 10 18:14:46 2012
New Revision: 147900

URL: http://llvm.org/viewvc/llvm-project?rev=147900&view=rev
Log:
Do placeholder conversions on array bounds in both declarators and
new-expressions.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaObjC/property.m
    cfe/trunk/test/SemaObjCXX/properties.mm

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=147900&r1=147899&r2=147900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Jan 10 18:14:46 2012
@@ -1010,10 +1010,13 @@
   // C++ 5.3.4p6: "The expression in a direct-new-declarator shall have integral
   //   or enumeration type with a non-negative value."
   if (ArraySize && !ArraySize->isTypeDependent()) {
+    // Eliminate placeholders.
+    ExprResult ConvertedSize = CheckPlaceholderExpr(ArraySize);
+    if (ConvertedSize.isInvalid())
+      return ExprError();
+    ArraySize = ConvertedSize.take();
 
-    QualType SizeType = ArraySize->getType();
-
-    ExprResult ConvertedSize = ConvertToIntegralOrEnumerationType(
+    ConvertedSize = ConvertToIntegralOrEnumerationType(
       StartLoc, ArraySize,
       PDiag(diag::err_array_size_not_integral),
       PDiag(diag::err_array_size_incomplete_type)
@@ -1029,7 +1032,7 @@
       return ExprError();
 
     ArraySize = ConvertedSize.take();
-    SizeType = ArraySize->getType();
+    QualType SizeType = ArraySize->getType();
     if (!SizeType->isIntegralOrUnscopedEnumerationType())
       return ExprError();
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=147900&r1=147899&r2=147900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Jan 10 18:14:46 2012
@@ -1267,6 +1267,13 @@
     return QualType();
   }
 
+  // Do placeholder conversions on the array size expression.
+  if (ArraySize && ArraySize->hasPlaceholderType()) {
+    ExprResult Result = CheckPlaceholderExpr(ArraySize);
+    if (Result.isInvalid()) return QualType();
+    ArraySize = Result.take();
+  }
+
   // Do lvalue-to-rvalue conversions on the array size expression.
   if (ArraySize && !ArraySize->isRValue()) {
     ExprResult Result = DefaultLvalueConversion(ArraySize);

Modified: cfe/trunk/test/SemaObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property.m?rev=147900&r1=147899&r2=147900&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property.m (original)
+++ cfe/trunk/test/SemaObjC/property.m Tue Jan 10 18:14:46 2012
@@ -74,3 +74,10 @@
 + (float) globalValue { return 5.0f; }
 + (float) gv { return test6_getClass().globalValue; }
 @end
+
+ at interface Test7
+ at property unsigned length;
+ at end
+void test7(Test7 *t) {
+  char data[t.length] = {}; // expected-error {{variable-sized object may not be initialized}}
+}

Modified: cfe/trunk/test/SemaObjCXX/properties.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/properties.mm?rev=147900&r1=147899&r2=147900&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/properties.mm (original)
+++ cfe/trunk/test/SemaObjCXX/properties.mm Tue Jan 10 18:14:46 2012
@@ -31,3 +31,12 @@
   auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} expected-error {{variable 'y' with type 'auto' has incompatible initializer of type}}
   auto z = a.z;
 }
+
+// rdar://problem/10672108
+ at interface Test3
+- (int) length;
+ at end
+void test3(Test3 *t) {
+  char vla[t.length] = {};
+  char *heaparray = new char[t.length]; // expected-error {{variable-sized object may not be initialized}}
+}





More information about the cfe-commits mailing list