]> granicus.if.org Git - clang/commitdiff
block IRgen - Fixes a crash when determining if given block variable
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Aug 2011 00:27:49 +0000 (00:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 23 Aug 2011 00:27:49 +0000 (00:27 +0000)
is captured by a given statement expression. // rdar://10001085

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

lib/CodeGen/CGDecl.cpp
test/CodeGen/block-3.c [new file with mode: 0644]

index 6e65e88bceb9b908dc577e6261c335dff350f8d4..6be6fcedd36c92a53c92b546617d4f9dc0758794 100644 (file)
@@ -875,6 +875,9 @@ static bool isCapturedBy(const VarDecl &var, const Expr *e) {
     return false;
   }
 
+  if (const StmtExpr *SE = dyn_cast<StmtExpr>(e))
+    e = cast<Expr>(SE->getSubStmt()->body_back());
+    
   for (Stmt::const_child_range children = e->children(); children; ++children)
     if (isCapturedBy(var, cast<Expr>(*children)))
       return true;
diff --git a/test/CodeGen/block-3.c b/test/CodeGen/block-3.c
new file mode 100644 (file)
index 0000000..95cb6a7
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 
+// rdar://10001085
+
+int main() {
+  ^{
+                __attribute__((__blocks__(byref))) int index = ({ int __a; int __b; __a < __b ? __b : __a; });
+   };
+}