summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-02-11 06:29:29 +0000
committerTed Kremenek <kremenek@apple.com>2014-02-11 06:29:29 +0000
commita683f639c7e24408409c6d07979ba171e2581653 (patch)
tree17e70cbc6e752490dc486c8c975b855dc4b54ab6
parentbf987c2dae19ff8bf4818292fb7f424c611592af (diff)
downloadbcm5719-llvm-a683f639c7e24408409c6d07979ba171e2581653.tar.gz
bcm5719-llvm-a683f639c7e24408409c6d07979ba171e2581653.zip
Fix PCH deserialization bug with local static symbols being treated as local extern.
This triggered a miscompilation of code using Boost's function_template.hpp when it was included inside a PCH file. A local static within that header would be treated as local extern, resulting in the wrong mangling. This only occurred during PCH deserialization. Fixes <rdar://problem/15975816> and <rdar://problem/15926311>. llvm-svn: 201130
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp2
-rw-r--r--clang/test/PCH/local_static.cpp20
-rw-r--r--clang/test/PCH/local_static.h7
3 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 943328b9cdc..18dbb053b99 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -973,7 +973,7 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
VD->setCachedLinkage(VarLinkage);
// Reconstruct the one piece of the IdentifierNamespace that we need.
- if (VarLinkage != NoLinkage &&
+ if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage &&
VD->getLexicalDeclContext()->isFunctionOrMethod())
VD->setLocalExternDecl();
diff --git a/clang/test/PCH/local_static.cpp b/clang/test/PCH/local_static.cpp
new file mode 100644
index 00000000000..1085d81d317
--- /dev/null
+++ b/clang/test/PCH/local_static.cpp
@@ -0,0 +1,20 @@
+// Test this without PCH.
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -include %S/local_static.h -fsyntax-only %s -emit-llvm -o %t.no_pch.ll %s
+// RUN: FileCheck --input-file %t.no_pch.ll %s
+
+// Test with PCH.
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -x c++-header -emit-pch -o %t.pch %S/local_static.h
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -include-pch %t.pch -emit-llvm -o %t.pch.ll %s
+// RUN: FileCheck --input-file %t.pch.ll %s
+
+void test(Bar &b) {
+ b.f<int>();
+ static int s;
+}
+
+// Check if the mangling of static and local extern variables
+// are correct and preserved by PCH.
+
+// CHECK: @_ZZ4testR3BarE1s = internal global i32 0, align 4
+// CHECK: @_ZZN3Bar1fIiEEvvE1y = linkonce_odr constant i32 0, align 4
+
diff --git a/clang/test/PCH/local_static.h b/clang/test/PCH/local_static.h
new file mode 100644
index 00000000000..a69382adf83
--- /dev/null
+++ b/clang/test/PCH/local_static.h
@@ -0,0 +1,7 @@
+class Bar {
+public:
+ template<typename T>
+ void f() {
+ static const T y = 0;
+ }
+};
OpenPOWER on IntegriCloud