[cfe-commits] r138824 - in /cfe/trunk: lib/Serialization/ASTWriter.cpp test/PCH/Inputs/cxx-method.h test/PCH/cxx-method.cpp

Douglas Gregor dgregor at apple.com
Tue Aug 30 13:49:19 PDT 2011


Author: dgregor
Date: Tue Aug 30 15:49:19 2011
New Revision: 138824

URL: http://llvm.org/viewvc/llvm-project?rev=138824&view=rev
Log:
When writing out the entries in a lookup table for a DeclContext, make
sure that all of the CXXConversionDecls go into the same
bucket. Otherwise, name lookup might not find them all. Fixes
<rdar://problem/10041960>.

Added:
    cfe/trunk/test/PCH/Inputs/cxx-method.h
Modified:
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/PCH/cxx-method.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=138824&r1=138823&r2=138824&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Aug 30 15:49:19 2011
@@ -2624,14 +2624,37 @@
   ASTDeclContextNameLookupTrait Trait(*this);
 
   // Create the on-disk hash table representation.
+  DeclarationName ConversionName;
+  llvm::SmallVector<NamedDecl *, 4> ConversionDecls;
   for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
        D != DEnd; ++D) {
     DeclarationName Name = D->first;
     DeclContext::lookup_result Result = D->second.getLookupResult();
-    if (Result.first != Result.second)
+    if (Result.first != Result.second) {
+      if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) {
+        // Hash all conversion function names to the same name. The actual
+        // type information in conversion function name is not used in the
+        // key (since such type information is not stable across different
+        // modules), so the intended effect is to coalesce all of the conversion
+        // functions under a single key.
+        if (!ConversionName)
+          ConversionName = Name;
+        ConversionDecls.append(Result.first, Result.second);
+        continue;
+      }
+      
       Generator.insert(Name, Result, Trait);
+    }
   }
 
+  // Add the conversion functions
+  if (!ConversionDecls.empty()) {
+    Generator.insert(ConversionName, 
+                     DeclContext::lookup_result(ConversionDecls.begin(),
+                                                ConversionDecls.end()),
+                     Trait);
+  }
+  
   // Create the on-disk hash table in a buffer.
   llvm::SmallString<4096> LookupTable;
   uint32_t BucketOffset;

Added: cfe/trunk/test/PCH/Inputs/cxx-method.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/cxx-method.h?rev=138824&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/cxx-method.h (added)
+++ cfe/trunk/test/PCH/Inputs/cxx-method.h Tue Aug 30 15:49:19 2011
@@ -0,0 +1,6 @@
+struct S {
+  void m(int x);
+
+  operator const char*();
+  operator char*();
+};

Modified: cfe/trunk/test/PCH/cxx-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-method.cpp?rev=138824&r1=138823&r2=138824&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx-method.cpp (original)
+++ cfe/trunk/test/PCH/cxx-method.cpp Tue Aug 30 15:49:19 2011
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-pch %s -o %t
-
-struct S {
-  void m(int x);
-};
+// RUN: %clang_cc1 -x c++ -emit-pch %S/Inputs/cxx-method.h -o %t
+// RUN: %clang_cc1 -include-pch %t -verify %s
 
 void S::m(int x) { }
+
+S::operator char *() { return 0; }
+
+S::operator const char *() { return 0; }





More information about the cfe-commits mailing list