]> granicus.if.org Git - clang/commitdiff
Fixed a crash specific to blocks in c++ uncovered by an internal
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Feb 2010 20:31:02 +0000 (20:31 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Feb 2010 20:31:02 +0000 (20:31 +0000)
test suite.

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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/blocks-1.cpp [new file with mode: 0644]

index 4098d0f2cf2df743c595eb61cc1c8c9c1211c548..3cbba8c9ff55ac16be7d0e0c745e77a66a9f3943 100644 (file)
@@ -2221,7 +2221,9 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) {
     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);
diff --git a/test/SemaCXX/blocks-1.cpp b/test/SemaCXX/blocks-1.cpp
new file mode 100644 (file)
index 0000000..d93997a
--- /dev/null
@@ -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;
+}