r201130 - Fix PCH deserialization bug with local static symbols being treated as local extern.

Ted Kremenek kremenek at apple.com
Mon Feb 10 22:29:29 PST 2014


Author: kremenek
Date: Tue Feb 11 00:29:29 2014
New Revision: 201130

URL: http://llvm.org/viewvc/llvm-project?rev=201130&view=rev
Log:
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>.

Added:
    cfe/trunk/test/PCH/local_static.cpp
    cfe/trunk/test/PCH/local_static.h
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=201130&r1=201129&r2=201130&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Feb 11 00:29:29 2014
@@ -973,7 +973,7 @@ ASTDeclReader::RedeclarableResult ASTDec
   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();
 

Added: cfe/trunk/test/PCH/local_static.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/local_static.cpp?rev=201130&view=auto
==============================================================================
--- cfe/trunk/test/PCH/local_static.cpp (added)
+++ cfe/trunk/test/PCH/local_static.cpp Tue Feb 11 00:29:29 2014
@@ -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
+

Added: cfe/trunk/test/PCH/local_static.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/local_static.h?rev=201130&view=auto
==============================================================================
--- cfe/trunk/test/PCH/local_static.h (added)
+++ cfe/trunk/test/PCH/local_static.h Tue Feb 11 00:29:29 2014
@@ -0,0 +1,7 @@
+class Bar {
+public:
+  template<typename T>
+  void f() {
+    static const T y = 0;
+  }
+};





More information about the cfe-commits mailing list