From: Richard Smith Date: Tue, 26 Apr 2016 23:40:43 +0000 (+0000) Subject: PR27513: When determining which declaration to put into an exported lookup X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca0241ca1e5404add33ab97c2c4369bf03f2075a;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267632 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index e99beb360d..073ed67474 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3107,11 +3107,20 @@ static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, 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(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()) { diff --git a/test/Modules/Inputs/PR27513/a.h b/test/Modules/Inputs/PR27513/a.h new file mode 100644 index 0000000000..7eecbf4773 --- /dev/null +++ b/test/Modules/Inputs/PR27513/a.h @@ -0,0 +1,5 @@ +#include "b.h" + +inline void f() { basic_string s; } + +#include "c.h" diff --git a/test/Modules/Inputs/PR27513/b.h b/test/Modules/Inputs/PR27513/b.h new file mode 100644 index 0000000000..b514c1e347 --- /dev/null +++ b/test/Modules/Inputs/PR27513/b.h @@ -0,0 +1,3 @@ +#include "mystring.h" +#include "b1.h" +#include "b2.h" diff --git a/test/Modules/Inputs/PR27513/b1.h b/test/Modules/Inputs/PR27513/b1.h new file mode 100644 index 0000000000..a12b29f71b --- /dev/null +++ b/test/Modules/Inputs/PR27513/b1.h @@ -0,0 +1 @@ +#include "b11.h" diff --git a/test/Modules/Inputs/PR27513/b11.h b/test/Modules/Inputs/PR27513/b11.h new file mode 100644 index 0000000000..e7bfaec9ce --- /dev/null +++ b/test/Modules/Inputs/PR27513/b11.h @@ -0,0 +1,2 @@ +#include "mystring.h" +#include "b111.h" diff --git a/test/Modules/Inputs/PR27513/b111.h b/test/Modules/Inputs/PR27513/b111.h new file mode 100644 index 0000000000..b7a63b5c23 --- /dev/null +++ b/test/Modules/Inputs/PR27513/b111.h @@ -0,0 +1,3 @@ +#include "mystring.h" +#include "b1111.h" +#include "b1112.h" diff --git a/test/Modules/Inputs/PR27513/b1111.h b/test/Modules/Inputs/PR27513/b1111.h new file mode 100644 index 0000000000..3f9cf449b3 --- /dev/null +++ b/test/Modules/Inputs/PR27513/b1111.h @@ -0,0 +1 @@ +#include "mystring.h" diff --git a/test/Modules/Inputs/PR27513/b1112.h b/test/Modules/Inputs/PR27513/b1112.h new file mode 100644 index 0000000000..3f9cf449b3 --- /dev/null +++ b/test/Modules/Inputs/PR27513/b1112.h @@ -0,0 +1 @@ +#include "mystring.h" diff --git a/test/Modules/Inputs/PR27513/b2.h b/test/Modules/Inputs/PR27513/b2.h new file mode 100644 index 0000000000..3f9cf449b3 --- /dev/null +++ b/test/Modules/Inputs/PR27513/b2.h @@ -0,0 +1 @@ +#include "mystring.h" diff --git a/test/Modules/Inputs/PR27513/c.h b/test/Modules/Inputs/PR27513/c.h new file mode 100644 index 0000000000..3f9cf449b3 --- /dev/null +++ b/test/Modules/Inputs/PR27513/c.h @@ -0,0 +1 @@ +#include "mystring.h" diff --git a/test/Modules/Inputs/PR27513/module.modulemap b/test/Modules/Inputs/PR27513/module.modulemap new file mode 100644 index 0000000000..ee2a9ce4aa --- /dev/null +++ b/test/Modules/Inputs/PR27513/module.modulemap @@ -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 *} diff --git a/test/Modules/Inputs/PR27513/mystring.h b/test/Modules/Inputs/PR27513/mystring.h new file mode 100644 index 0000000000..95680ed883 --- /dev/null +++ b/test/Modules/Inputs/PR27513/mystring.h @@ -0,0 +1,8 @@ +#ifndef _GLIBCXX_STRING +#define _GLIBCXX_STRING +template struct basic_string { + struct _Alloc_hider {} _M_dataplus; + ~basic_string() { _Alloc_hider h; } +}; +extern template class basic_string; +#endif diff --git a/test/Modules/pr27513.cpp b/test/Modules/pr27513.cpp new file mode 100644 index 0000000000..28fbe5bd82 --- /dev/null +++ b/test/Modules/pr27513.cpp @@ -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