]> granicus.if.org Git - clang/commitdiff
When compiling C++ code, always mangle the names of static block var decls.
authorAnders Carlsson <andersca@mac.com>
Thu, 2 Apr 2009 03:29:47 +0000 (03:29 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 2 Apr 2009 03:29:47 +0000 (03:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68280 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp

index 5a5bb62b0633275160cd07632c5be83fbf6fb885..1277404e169776e1569233711ba54ba121d714d2 100644 (file)
@@ -86,19 +86,25 @@ CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D,
   QualType Ty = D.getType();
   assert(Ty->isConstantSizeType() && "VLAs can't be static");
 
-  std::string ContextName;
-  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl))
-    ContextName = CGM.getMangledName(FD);
-  else if (isa<ObjCMethodDecl>(CurFuncDecl))
-    ContextName = std::string(CurFn->getNameStart(), 
-                              CurFn->getNameStart() + CurFn->getNameLen());
-  else
-    assert(0 && "Unknown context for block var decl");
+  std::string Name;
+  if (getContext().getLangOptions().CPlusPlus) {
+    Name = CGM.getMangledName(&D);
+  } else {
+    std::string ContextName;
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl))
+      ContextName = CGM.getMangledName(FD);
+    else if (isa<ObjCMethodDecl>(CurFuncDecl))
+      ContextName = std::string(CurFn->getNameStart(), 
+                                CurFn->getNameStart() + CurFn->getNameLen());
+    else
+      assert(0 && "Unknown context for block var decl");
+    
+    Name = ContextName + Separator + D.getNameAsString();
+  }
 
   const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
   return new llvm::GlobalVariable(LTy, Ty.isConstant(getContext()), Linkage,
-                                  llvm::Constant::getNullValue(LTy), 
-                                  ContextName + Separator + D.getNameAsString(),
+                                  llvm::Constant::getNullValue(LTy), Name,
                                   &CGM.getModule(), 0, Ty.getAddressSpace());
 }