[cfe-commits] r160089 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/CodeGenObjCXX/blocks.mm

Nico Weber nicolasweber at gmx.de
Wed Jul 11 15:50:15 PDT 2012


Author: nico
Date: Wed Jul 11 17:50:15 2012
New Revision: 160089

URL: http://llvm.org/viewvc/llvm-project?rev=160089&view=rev
Log:
Don't try to do RVO on block variables that refer to an enclosing local.

Fixes PR13314, clang crashing on blocks refering to an enclosing local
when the enclosing function returns void.


Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/CodeGenObjCXX/blocks.mm

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=160089&r1=160088&r2=160089&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Jul 11 17:50:15 2012
@@ -2035,7 +2035,7 @@
   // ... the expression is the name of a non-volatile automatic object
   // (other than a function or catch-clause parameter)) ...
   const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E->IgnoreParens());
-  if (!DR)
+  if (!DR || DR->refersToEnclosingLocal())
     return 0;
   const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl());
   if (!VD)

Modified: cfe/trunk/test/CodeGenObjCXX/blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/blocks.mm?rev=160089&r1=160088&r2=160089&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/blocks.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/blocks.mm Wed Jul 11 17:50:15 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 %s -verify -emit-llvm -o %t
+// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 %s -verify -std=c++11 -emit-llvm -o %t
 // rdar://8979379
 
 @interface A
@@ -30,7 +30,7 @@
 
 // Test4
 struct S {
-  S *(^a)() = ^{ // expected-warning {{C++11}}
+  S *(^a)() = ^{
     return this;
   };
 };
@@ -40,7 +40,22 @@
 struct X {
   void f() {
     ^ {
-      struct Nested { Nested *ptr = this; }; // expected-warning {{C++11}}
+      struct Nested { Nested *ptr = this; };
     } ();
   };
 };
+
+// Regression test for PR13314
+class FooClass { };
+void fun() {
+  FooClass foovar;
+  ^() {  // expected-warning {{expression result unused}}
+    return foovar;
+  };
+}
+void gun() {
+  FooClass foovar;
+  [=]() {  // expected-warning {{expression result unused}}
+    return foovar;
+  };
+}





More information about the cfe-commits mailing list