]> granicus.if.org Git - clang/commitdiff
Fix for http://llvm.org/PR23392: magick/feature.c from ImageMagick-6.9.1-2 ICEs.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 7 May 2015 06:28:46 +0000 (06:28 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 7 May 2015 06:28:46 +0000 (06:28 +0000)
Fix for codegen of static variables declared inside of captured statements. Captured statements are actually a transparent DeclContexts, so we have to skip them when trying to get a mangled name for statics.
Differential Revision: http://reviews.llvm.org/D9522

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

lib/CodeGen/CGDecl.cpp
test/CodeGen/captured-statements.c
test/CodeGenCXX/captured-statements.cpp

index 874cf6938090f130eb470acbf67f479187d440b6..fdbf1f62d7c90f8dca7eeb356114c11b5fc90982 100644 (file)
@@ -156,6 +156,8 @@ static std::string getStaticDeclName(CodeGenModule &CGM, const VarDecl &D) {
   assert(!D.isExternallyVisible() && "name shouldn't matter");
   std::string ContextName;
   const DeclContext *DC = D.getDeclContext();
+  if (auto *CD = dyn_cast<CapturedDecl>(DC))
+    DC = cast<DeclContext>(CD->getNonClosureContext());
   if (const auto *FD = dyn_cast<FunctionDecl>(DC))
     ContextName = CGM.getMangledName(FD);
   else if (const auto *BD = dyn_cast<BlockDecl>(DC))
index 64af3c06047d756e3f57cfc4fbed4968667767b8..53861097d7cc81c79be963d8fa2444b738fedaea 100644 (file)
@@ -14,9 +14,12 @@ void test1() {
   int i = 0;
   #pragma clang __debug captured
   {
+    static float inner = 3.0;
+    (void)inner;
     i++;
   }
   // CHECK-1: %struct.anon = type { i32* }
+  // CHECK-1: {{.+}} global float 3.0
   //
   // CHECK-1: test1
   // CHECK-1: alloca %struct.anon
index 56fe4c61c9868d7e59b4fe2b44d2435b396bc87d..058e737893894fc21246d84bb1977ef08cea4c8e 100644 (file)
@@ -21,6 +21,8 @@ struct TestClass {
     Foo f;
     #pragma clang __debug captured
     {
+      static double inner = x;
+      (void)inner;
       f.y = x;
     }
   }
@@ -29,22 +31,26 @@ struct TestClass {
 void test1() {
   TestClass c;
   c.MemberFunc();
-  // CHECK-1: %[[Capture:struct\.anon[\.0-9]*]] = type { %struct.Foo*, %struct.TestClass* }
+  // CHECK-1: %[[Capture:struct\.anon[\.0-9]*]] = type { %struct.TestClass*, %struct.Foo* }
+  // CHECK-1: [[INNER:@.+]] = {{.+}} global double
 
   // CHECK-1: define {{.*}} void @_ZN9TestClass10MemberFuncEv
   // CHECK-1:   alloca %struct.anon
   // CHECK-1:   getelementptr inbounds %[[Capture]], %[[Capture]]* %{{[^,]*}}, i32 0, i32 0
-  // CHECK-1:   store %struct.Foo* %f, %struct.Foo**
   // CHECK-1:   getelementptr inbounds %[[Capture]], %[[Capture]]* %{{[^,]*}}, i32 0, i32 1
+  // CHECK-1:   store %struct.Foo* %f, %struct.Foo**
   // CHECK-1:   call void @[[HelperName:[A-Za-z0-9_]+]](%[[Capture]]*
   // CHECK-1:   call {{.*}}FooD1Ev
   // CHECK-1:   ret
 }
 
 // CHECK-1: define internal void @[[HelperName]]
-// CHECK-1:   getelementptr inbounds %[[Capture]], %[[Capture]]* {{[^,]*}}, i32 0, i32 1
-// CHECK-1:   getelementptr inbounds %struct.TestClass, %struct.TestClass* {{[^,]*}}, i32 0, i32 0
 // CHECK-1:   getelementptr inbounds %[[Capture]], %[[Capture]]* {{[^,]*}}, i32 0, i32 0
+// CHECK-1:   call i32 @__cxa_guard_acquire(
+// CHECK-1:   store double %{{.+}}, double* [[INNER]],
+// CHECK-1:   call void @__cxa_guard_release(
+// CHECK-1:   getelementptr inbounds %struct.TestClass, %struct.TestClass* {{[^,]*}}, i32 0, i32 0
+// CHECK-1:   getelementptr inbounds %[[Capture]], %[[Capture]]* {{[^,]*}}, i32 0, i32 1
 
 void test2(int x) {
   int y = [&]() {