r267632 - PR27513: When determining which declaration to put into an exported lookup

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 16:40:44 PDT 2016


Author: rsmith
Date: Tue Apr 26 18:40:43 2016
New Revision: 267632

URL: http://llvm.org/viewvc/llvm-project?rev=267632&view=rev
Log:
PR27513: When determining which declaration to put into an exported lookup
table for a module / PCH, never map from a normal declaration of a class to an
injected-class-name declaration (or vice versa). Those declarations live in
distinct lookup tables and should not be confused.

We really shouldn't be using a CXXRecordDecl to represent an
injected-class-name in the first place; I've filed PR27532 so we don't forget.

Added:
    cfe/trunk/test/Modules/Inputs/PR27513/
    cfe/trunk/test/Modules/Inputs/PR27513/a.h
    cfe/trunk/test/Modules/Inputs/PR27513/b.h
    cfe/trunk/test/Modules/Inputs/PR27513/b1.h
    cfe/trunk/test/Modules/Inputs/PR27513/b11.h
    cfe/trunk/test/Modules/Inputs/PR27513/b111.h
    cfe/trunk/test/Modules/Inputs/PR27513/b1111.h
    cfe/trunk/test/Modules/Inputs/PR27513/b1112.h
    cfe/trunk/test/Modules/Inputs/PR27513/b2.h
    cfe/trunk/test/Modules/Inputs/PR27513/c.h
    cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap
    cfe/trunk/test/Modules/Inputs/PR27513/mystring.h
    cfe/trunk/test/Modules/pr27513.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=267632&r1=267631&r2=267632&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Apr 26 18:40:43 2016
@@ -3107,11 +3107,20 @@ static NamedDecl *getDeclForLocalLookup(
   if (Decl *Redecl = D->getPreviousDecl()) {
     // For Redeclarable decls, a prior declaration might be local.
     for (; Redecl; Redecl = Redecl->getPreviousDecl()) {
-      if (!Redecl->isFromASTFile())
+      // If we find a local decl, we're done.
+      if (!Redecl->isFromASTFile()) {
+        // Exception: in very rare cases (for injected-class-names), not all
+        // redeclarations are in the same semantic context. Skip ones in a
+        // different context. They don't go in this lookup table at all.
+        if (!Redecl->getDeclContext()->getRedeclContext()->Equals(
+                D->getDeclContext()->getRedeclContext()))
+          continue;
         return cast<NamedDecl>(Redecl);
+      }
+
       // If we find a decl from a (chained-)PCH stop since we won't find a
       // local one.
-      if (D->getOwningModuleID() == 0)
+      if (Redecl->getOwningModuleID() == 0)
         break;
     }
   } else if (Decl *First = D->getCanonicalDecl()) {

Added: cfe/trunk/test/Modules/Inputs/PR27513/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/a.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/a.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,5 @@
+#include "b.h"
+
+inline void f() { basic_string<char> s; }
+
+#include "c.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,3 @@
+#include "mystring.h"
+#include "b1.h"
+#include "b2.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b1.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b1.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b1.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "b11.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b11.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b11.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b11.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b11.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,2 @@
+#include "mystring.h"
+#include "b111.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b111.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b111.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b111.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b111.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,3 @@
+#include "mystring.h"
+#include "b1111.h"
+#include "b1112.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b1111.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b1111.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b1111.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b1111.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "mystring.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b1112.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b1112.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b1112.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b1112.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "mystring.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b2.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/b2.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b2.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "mystring.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/c.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/c.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "mystring.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap Tue Apr 26 18:40:43 2016
@@ -0,0 +1,7 @@
+module "c.h" {header "c.h" export *}
+module "b2.h" { header "b2.h" export *}
+module "b.h" {header "b.h" export *}
+module "b111.h" { header "b111.h" export *}
+module "b11.h" { header "b11.h" export *}
+module "b1111.h" { header "b1111.h" export *}
+module "b1112.h" { header "b1112.h" export *}

Added: cfe/trunk/test/Modules/Inputs/PR27513/mystring.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/mystring.h?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR27513/mystring.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/mystring.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,8 @@
+#ifndef _GLIBCXX_STRING
+#define _GLIBCXX_STRING
+template<typename> struct basic_string {
+  struct _Alloc_hider {} _M_dataplus;
+  ~basic_string() { _Alloc_hider h; } 
+};
+extern template class basic_string<char>;
+#endif

Added: cfe/trunk/test/Modules/pr27513.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr27513.cpp?rev=267632&view=auto
==============================================================================
--- cfe/trunk/test/Modules/pr27513.cpp (added)
+++ cfe/trunk/test/Modules/pr27513.cpp Tue Apr 26 18:40:43 2016
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR27513 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR27513/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR27513 -verify %s
+
+#include "Inputs/PR27513/a.h"
+
+//expected-no-diagnostics




More information about the cfe-commits mailing list