diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2013-01-26 00:35:08 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2013-01-26 00:35:08 +0000 |
commit | 01a41140cd8ec9475ed0c33384310fbdd3b6de11 (patch) | |
tree | c14db552cc993c35c59e4477a3f7b7656b149ce0 /lib | |
parent | 3ac83d69c61238cd0d38e90fcdd03390530ab2fb (diff) | |
download | clang-01a41140cd8ec9475ed0c33384310fbdd3b6de11.tar.gz |
Preserve Sema::UndefinedInternals across PCH boundaries. Fixes
-Wundefined-internal warnings with PCH.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/MultiplexExternalSemaSource.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 24 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 2 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 30 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 17 |
5 files changed, 60 insertions, 19 deletions
diff --git a/lib/Sema/MultiplexExternalSemaSource.cpp b/lib/Sema/MultiplexExternalSemaSource.cpp index bee69c46e5..8df830aeff 100644 --- a/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/lib/Sema/MultiplexExternalSemaSource.cpp @@ -200,6 +200,12 @@ void MultiplexExternalSemaSource::ReadKnownNamespaces( for(size_t i = 0; i < Sources.size(); ++i) Sources[i]->ReadKnownNamespaces(Namespaces); } + +void MultiplexExternalSemaSource::ReadUndefinedInternals( + llvm::MapVector<NamedDecl*, SourceLocation> &Undefined){ + for(size_t i = 0; i < Sources.size(); ++i) + Sources[i]->ReadUndefinedInternals(Undefined); +} bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ for(size_t i = 0; i < Sources.size(); ++i) diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index c03d41eb04..c0482767ca 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -385,7 +385,7 @@ static void checkUndefinedInternals(Sema &S) { // Collect all the still-undefined entities with internal linkage. SmallVector<UndefinedInternal, 16> undefined; - for (llvm::DenseMap<NamedDecl*,SourceLocation>::iterator + for (llvm::MapVector<NamedDecl*,SourceLocation>::iterator i = S.UndefinedInternals.begin(), e = S.UndefinedInternals.end(); i != e; ++i) { NamedDecl *decl = i->first; @@ -407,23 +407,9 @@ static void checkUndefinedInternals(Sema &S) { continue; } - // We build a FullSourceLoc so that we can sort with array_pod_sort. - FullSourceLoc loc(i->second, S.Context.getSourceManager()); - undefined.push_back(UndefinedInternal(decl, loc)); - } - - if (undefined.empty()) return; - - // Sort (in order of use site) so that we're not (as) dependent on - // the iteration order through an llvm::DenseMap. - llvm::array_pod_sort(undefined.begin(), undefined.end()); - - for (SmallVectorImpl<UndefinedInternal>::iterator - i = undefined.begin(), e = undefined.end(); i != e; ++i) { - NamedDecl *decl = i->decl; S.Diag(decl->getLocation(), diag::warn_undefined_internal) << isa<VarDecl>(decl) << decl; - S.Diag(i->useLoc, diag::note_used_here); + S.Diag(i->second, diag::note_used_here); } } @@ -736,6 +722,8 @@ void Sema::ActOnEndOfTranslationUnit() { } } + if (ExternalSource) + ExternalSource->ReadUndefinedInternals(UndefinedInternals); checkUndefinedInternals(*this); } @@ -1080,6 +1068,10 @@ void ExternalSemaSource::ReadKnownNamespaces( SmallVectorImpl<NamespaceDecl *> &Namespaces) { } +void ExternalSemaSource::ReadUndefinedInternals( + llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { +} + void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const { SourceLocation Loc = this->Loc; if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation(); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 4bdc1dc253..a4228a5058 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3857,7 +3857,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, KnownNamespaces[ExternalKnownNamespaces[I]] = true; } - for (llvm::DenseMap<NamespaceDecl*, bool>::iterator + for (llvm::MapVector<NamespaceDecl*, bool>::iterator KNI = KnownNamespaces.begin(), KNIEnd = KnownNamespaces.end(); KNI != KNIEnd; ++KNI) diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index fd1b8966ee..0261ad8f48 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2461,7 +2461,24 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { for (unsigned I = 0, N = Record.size(); I != N; ++I) KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); break; - + + case UNDEFINED_INTERNALS: + if (UndefinedInternals.size() % 2 != 0) { + Error("Invalid existing UndefinedInternals"); + return true; + } + + if (Record.size() % 2 != 0) { + Error("invalid undefined internals record"); + return true; + } + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + UndefinedInternals.push_back(getGlobalDeclID(F, Record[I++])); + UndefinedInternals.push_back( + ReadSourceLocation(F, Record, I).getRawEncoding()); + } + break; + case IMPORTED_MODULES: { if (F.Kind != MK_Module) { // If we aren't loading a module (which has its own exports), make @@ -5934,6 +5951,17 @@ void ASTReader::ReadKnownNamespaces( } } +void ASTReader::ReadUndefinedInternals( + llvm::MapVector<NamedDecl*, SourceLocation> &Undefined) { + for (unsigned Idx = 0, N = UndefinedInternals.size(); Idx != N;) { + NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedInternals[Idx++])); + SourceLocation Loc = + SourceLocation::getFromRawEncoding(UndefinedInternals[Idx++]); + Undefined.insert(std::make_pair(D, Loc)); + } +} + + void ASTReader::ReadTentativeDefinitions( SmallVectorImpl<VarDecl *> &TentativeDefs) { for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 5a690b3ded..d398153324 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -824,6 +824,7 @@ void ASTWriter::WriteBlockInfoBlock() { RECORD(OPENCL_EXTENSIONS); RECORD(DELEGATING_CTORS); RECORD(KNOWN_NAMESPACES); + RECORD(UNDEFINED_INTERNALS); RECORD(MODULE_OFFSET_MAP); RECORD(SOURCE_MANAGER_LINE_TABLE); RECORD(OBJC_CATEGORIES_MAP); @@ -3581,7 +3582,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, // Build a record containing all of the known namespaces. RecordData KnownNamespaces; - for (llvm::DenseMap<NamespaceDecl*, bool>::iterator + for (llvm::MapVector<NamespaceDecl*, bool>::iterator I = SemaRef.KnownNamespaces.begin(), IEnd = SemaRef.KnownNamespaces.end(); I != IEnd; ++I) { @@ -3589,6 +3590,16 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, AddDeclRef(I->first, KnownNamespaces); } + // Build a record of all used, undefined objects with internal linkage. + RecordData UndefinedInternals; + for (llvm::MapVector<NamedDecl*, SourceLocation>::iterator + I = SemaRef.UndefinedInternals.begin(), + IEnd = SemaRef.UndefinedInternals.end(); + I != IEnd; ++I) { + AddDeclRef(I->first, UndefinedInternals); + AddSourceLocation(I->second, UndefinedInternals); + } + // Write the control block WriteControlBlock(PP, Context, isysroot, OutputFile); @@ -3803,6 +3814,10 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, // Write the known namespaces. if (!KnownNamespaces.empty()) Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); + + // Write the undefined internal functions and variables. + if (!UndefinedInternals.empty()) + Stream.EmitRecord(UNDEFINED_INTERNALS, UndefinedInternals); // Write the visible updates to DeclContexts. for (llvm::SmallPtrSet<const DeclContext *, 16>::iterator |