]> granicus.if.org Git - clang/commitdiff
Let CodeGenFunction::EmitVarDecl query the semantic storage class info.
authorEnea Zaffanella <zaffanella@cs.unipr.it>
Thu, 16 May 2013 11:27:56 +0000 (11:27 +0000)
committerEnea Zaffanella <zaffanella@cs.unipr.it>
Thu, 16 May 2013 11:27:56 +0000 (11:27 +0000)
Added testcase corresponding to PR15991.

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

lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/anonymous-namespaces.cpp

index 3ce6dec6a53c0c1441499daa51409a3ee08ef409..eb2b0e7e01051dabe57f862bd190704ba3b0eefa 100644 (file)
@@ -114,12 +114,7 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
 /// EmitVarDecl - This method handles emission of any variable declaration
 /// inside a function, including static vars etc.
 void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
-  switch (D.getStorageClass()) {
-  case SC_None:
-  case SC_Auto:
-  case SC_Register:
-    return EmitAutoVarDecl(D);
-  case SC_Static: {
+  if (D.isStaticLocal()) {
     llvm::GlobalValue::LinkageTypes Linkage =
       llvm::GlobalValue::InternalLinkage;
 
@@ -134,15 +129,16 @@ void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
 
     return EmitStaticVarDecl(D, Linkage);
   }
-  case SC_Extern:
-  case SC_PrivateExtern:
+
+  if (D.hasExternalStorage())
     // Don't emit it now, allow it to be emitted lazily on its first use.
     return;
-  case SC_OpenCLWorkGroupLocal:
+
+  if (D.getStorageClass() == SC_OpenCLWorkGroupLocal)
     return CGM.getOpenCLRuntime().EmitWorkGroupLocalVarDecl(*this, D);
-  }
 
-  llvm_unreachable("Unknown storage class");
+  assert(D.hasLocalStorage());
+  return EmitAutoVarDecl(D);
 }
 
 static std::string GetStaticDeclName(CodeGenFunction &CGF, const VarDecl &D,
index 32e17a35ff2ddb21570219ae2052d1955c55ef4b..e9d1921adaaf3c35c840e44d9329e3cc51e08c4b 100644 (file)
@@ -66,3 +66,12 @@ namespace test2 {
 
   // CHECK-2: define internal void @_ZN5test21A1BINS_12_GLOBAL__N_11CEE3fooEv()
 }
+
+namespace {
+
+int bar() {
+  extern int a;
+  return a;
+}
+
+} // namespace