On 05/14/2013 10:21 PM, Richard Smith wrote:
The call to hasExternalFormalLinkage in CGDecl.cpp should be to
hasExternalStorage. Consider:
namespace {
int a;
int f() {
extern int a;
return a;
}
}
Here, the 'a' inside 'f' has InternalLinkage but ExternalStorage. We
definitely don't want to emit that as an automatic-storage-duration
variable. Please also add an assert(D.hasLocalStorage()) before the call
to EmitAutoVarDecl.
Done as suggested (added both testcases).
Enea.
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp (revision 181760)
+++ lib/CodeGen/CGDecl.cpp (working copy)
@@ -117,12 +117,7 @@
/// 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;
@@ -137,15 +132,16 @@
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: test/SemaCXX/PR15991.cpp
===================================================================
--- test/SemaCXX/PR15991.cpp (revision 0)
+++ test/SemaCXX/PR15991.cpp (revision 0)
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-linux-gnu %s
+
+int foo() {
+ thread_local int n;
+ auto l = [] { return n; };
+ return l();
+}
+
+namespace {
+
+int a;
+
+int bar() {
+ extern int a;
+ return a;
+}
+
+} // namespace
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits