1278789SdimPull in r201130 from upstream clang trunk (by Ted Kremenek): 2278789Sdim 3278789Sdim Fix PCH deserialization bug with local static symbols being treated 4278789Sdim as local extern. 5278789Sdim 6278789Sdim This triggered a miscompilation of code using Boost's 7278789Sdim function_template.hpp when it was included inside a PCH file. A 8278789Sdim local static within that header would be treated as local extern, 9278789Sdim resulting in the wrong mangling. This only occurred during PCH 10278789Sdim deserialization. 11278789Sdim 12278789Sdim Fixes <rdar://problem/15975816> and <rdar://problem/15926311>. 13278789Sdim 14278789SdimThis fixes a crash in audio/murmur, which is using both PCH and Boost. 15278789Sdim 16278789SdimIntroduced here: http://svnweb.freebsd.org/changeset/base/278788 17278789Sdim 18278789SdimIndex: tools/clang/lib/Serialization/ASTReaderDecl.cpp 19278789Sdim=================================================================== 20278789Sdim--- tools/clang/lib/Serialization/ASTReaderDecl.cpp 21278789Sdim+++ tools/clang/lib/Serialization/ASTReaderDecl.cpp 22278789Sdim@@ -971,7 +971,7 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::V 23278789Sdim VD->setCachedLinkage(VarLinkage); 24278789Sdim 25278789Sdim // Reconstruct the one piece of the IdentifierNamespace that we need. 26278789Sdim- if (VarLinkage != NoLinkage && 27278789Sdim+ if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && 28278789Sdim VD->getLexicalDeclContext()->isFunctionOrMethod()) 29278789Sdim VD->setLocalExternDecl(); 30278789Sdim 31278789SdimIndex: tools/clang/test/PCH/local_static.cpp 32278789Sdim=================================================================== 33278789Sdim--- tools/clang/test/PCH/local_static.cpp 34278789Sdim+++ tools/clang/test/PCH/local_static.cpp 35278789Sdim@@ -0,0 +1,20 @@ 36278789Sdim+// Test this without PCH. 37278789Sdim+// 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 38278789Sdim+// RUN: FileCheck --input-file %t.no_pch.ll %s 39278789Sdim+ 40278789Sdim+// Test with PCH. 41278789Sdim+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -x c++-header -emit-pch -o %t.pch %S/local_static.h 42278789Sdim+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -include-pch %t.pch -emit-llvm -o %t.pch.ll %s 43278789Sdim+// RUN: FileCheck --input-file %t.pch.ll %s 44278789Sdim+ 45278789Sdim+void test(Bar &b) { 46278789Sdim+ b.f<int>(); 47278789Sdim+ static int s; 48278789Sdim+} 49278789Sdim+ 50278789Sdim+// Check if the mangling of static and local extern variables 51278789Sdim+// are correct and preserved by PCH. 52278789Sdim+ 53278789Sdim+// CHECK: @_ZZ4testR3BarE1s = internal global i32 0, align 4 54278789Sdim+// CHECK: @_ZZN3Bar1fIiEEvvE1y = linkonce_odr constant i32 0, align 4 55278789Sdim+ 56278789SdimIndex: tools/clang/test/PCH/local_static.h 57278789Sdim=================================================================== 58278789Sdim--- tools/clang/test/PCH/local_static.h 59278789Sdim+++ tools/clang/test/PCH/local_static.h 60278789Sdim@@ -0,0 +1,7 @@ 61278789Sdim+class Bar { 62278789Sdim+public: 63278789Sdim+ template<typename T> 64278789Sdim+ void f() { 65278789Sdim+ static const T y = 0; 66278789Sdim+ } 67278789Sdim+}; 68