[cfe-commits] r96608 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/blocks-1.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Feb 18 12:31:02 PST 2010


Author: fjahanian
Date: Thu Feb 18 14:31:02 2010
New Revision: 96608

URL: http://llvm.org/viewvc/llvm-project?rev=96608&view=rev
Log:
Fixed a crash specific to blocks in c++ uncovered by an internal
test suite.

Added:
    cfe/trunk/test/SemaCXX/blocks-1.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=96608&r1=96607&r2=96608&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Feb 18 14:31:02 2010
@@ -2221,7 +2221,9 @@
     QualType Ty = CE->getCallee()->getType();
     if (const PointerType *PT = Ty->getAs<PointerType>())
       Ty = PT->getPointeeType();
-    
+    else if (const BlockPointerType *BPT = Ty->getAs<BlockPointerType>())
+      Ty = BPT->getPointeeType();
+
     const FunctionType *FTy = Ty->getAs<FunctionType>();
     if (FTy->getResultType()->isReferenceType())
       return Owned(E);

Added: cfe/trunk/test/SemaCXX/blocks-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/blocks-1.cpp?rev=96608&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/blocks-1.cpp (added)
+++ cfe/trunk/test/SemaCXX/blocks-1.cpp Thu Feb 18 14:31:02 2010
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
+
+extern "C" int exit(int);
+
+typedef struct {
+    unsigned long ps[30];
+    int qs[30];
+} BobTheStruct;
+
+int main (int argc, const char * argv[]) {
+    BobTheStruct inny;
+    BobTheStruct outty;
+    BobTheStruct (^copyStruct)(BobTheStruct);
+    int i;
+    
+    for(i=0; i<30; i++) {
+        inny.ps[i] = i * i * i;
+        inny.qs[i] = -i * i * i;
+    }
+    
+    copyStruct = ^(BobTheStruct aBigStruct){ return aBigStruct; };  // pass-by-value intrinsically copies the argument
+    
+    outty = copyStruct(inny);
+
+    if ( &inny == &outty ) {
+        exit(1);
+    }
+    for(i=0; i<30; i++) {
+        if ( (inny.ps[i] != outty.ps[i]) || (inny.qs[i] != outty.qs[i]) ) {
+            exit(1);
+        }
+    }
+    
+    return 0;
+}





More information about the cfe-commits mailing list