r226765 - [modules] If we load two declarations with typedef names for linkage purposes
Richard Smith
richard-llvm at metafoo.co.uk
Wed Jan 21 18:21:23 PST 2015
Author: rsmith
Date: Wed Jan 21 20:21:23 2015
New Revision: 226765
URL: http://llvm.org/viewvc/llvm-project?rev=226765&view=rev
Log:
[modules] If we load two declarations with typedef names for linkage purposes
on top of a local declaration of the same entity, we still need to remember
that we loaded the first one or we may fail to merge the second one properly.
Added:
cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/
cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/a.h
cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h
cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap
cfe/trunk/test/Modules/merge-name-for-linkage.cc
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=226765&r1=226764&r2=226765&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Jan 21 20:21:23 2015
@@ -2554,15 +2554,21 @@ static DeclContext *getPrimaryContextFor
}
ASTDeclReader::FindExistingResult::~FindExistingResult() {
+ // Record that we had a typedef name for linkage whether or not we merge
+ // with that declaration.
+ if (TypedefNameForLinkage) {
+ DeclContext *DC = New->getDeclContext()->getRedeclContext();
+ Reader.ImportedTypedefNamesForLinkage.insert(
+ std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
+ return;
+ }
+
if (!AddResult || Existing)
return;
DeclarationName Name = New->getDeclName();
DeclContext *DC = New->getDeclContext()->getRedeclContext();
- if (TypedefNameForLinkage) {
- Reader.ImportedTypedefNamesForLinkage.insert(
- std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
- } else if (!Name) {
+ if (!Name) {
assert(needsAnonymousDeclarationNumber(New));
setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
AnonymousDeclNumber, New);
Added: cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/a.h?rev=226765&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/a.h Wed Jan 21 20:21:23 2015
@@ -0,0 +1 @@
+typedef union {} pthread_mutex_t;
Added: cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h?rev=226765&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/b.h Wed Jan 21 20:21:23 2015
@@ -0,0 +1 @@
+typedef union {} pthread_mutex_t;
Added: cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap?rev=226765&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/merge-name-for-linkage/module.modulemap Wed Jan 21 20:21:23 2015
@@ -0,0 +1,2 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
Added: cfe/trunk/test/Modules/merge-name-for-linkage.cc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-name-for-linkage.cc?rev=226765&view=auto
==============================================================================
--- cfe/trunk/test/Modules/merge-name-for-linkage.cc (added)
+++ cfe/trunk/test/Modules/merge-name-for-linkage.cc Wed Jan 21 20:21:23 2015
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-name-for-linkage -verify %s
+// expected-no-diagnostics
+typedef union {} pthread_mutex_t;
+#include "a.h"
+pthread_mutex_t x;
+#include "b.h"
+pthread_mutex_t y;
More information about the cfe-commits
mailing list