From: Fariborz Jahanian Date: Thu, 18 Feb 2010 20:31:02 +0000 (+0000) Subject: Fixed a crash specific to blocks in c++ uncovered by an internal X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b372b0ff1f1a0c6814163e0fe2f22f343bac87a8;p=clang Fixed a crash specific to blocks in c++ uncovered by an internal test suite. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96608 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 4098d0f2cf..3cbba8c9ff 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2221,7 +2221,9 @@ Sema::OwningExprResult Sema::MaybeBindToTemporary(Expr *E) { QualType Ty = CE->getCallee()->getType(); if (const PointerType *PT = Ty->getAs()) Ty = PT->getPointeeType(); - + else if (const BlockPointerType *BPT = Ty->getAs()) + Ty = BPT->getPointeeType(); + const FunctionType *FTy = Ty->getAs(); 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 index 0000000000..d93997ad68 --- /dev/null +++ b/test/SemaCXX/blocks-1.cpp @@ -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; +}