forked from OSchip/llvm-project
Support tentative definitions in precompiled headers. This isn't likely
to happen (ever), but at least we'll do the right thing when it does. llvm-svn: 69829
This commit is contained in:
parent
48db39dc90
commit
d4df8657b4
|
@ -134,7 +134,7 @@ namespace clang {
|
|||
|
||||
/// \brief Record code for the array of external definitions.
|
||||
///
|
||||
/// The PCH file contains a list of all of the external
|
||||
/// The PCH file contains a list of all of the unnamed external
|
||||
/// definitions present within the parsed headers, stored as an
|
||||
/// array of declaration IDs. These external definitions will be
|
||||
/// reported to the AST consumer after the PCH file has been
|
||||
|
@ -151,9 +151,12 @@ namespace clang {
|
|||
/// offsets into this record.
|
||||
SPECIAL_TYPES = 8,
|
||||
|
||||
/// \brief Record code for the block of extra statistics we
|
||||
/// gather while generating a PCH file.
|
||||
STATISTICS = 9
|
||||
/// \brief Record code for the extra statistics we gather while
|
||||
/// generating a PCH file.
|
||||
STATISTICS = 9,
|
||||
|
||||
/// \brief Record code for the array of tentative definitions.
|
||||
TENTATIVE_DEFINITIONS = 10
|
||||
};
|
||||
|
||||
/// \brief Record types used within a source manager block.
|
||||
|
|
|
@ -149,6 +149,10 @@ private:
|
|||
/// file.
|
||||
llvm::SmallVector<uint64_t, 16> ExternalDefinitions;
|
||||
|
||||
/// \brief The set of tentative definitions stored in the the PCH
|
||||
/// file.
|
||||
llvm::SmallVector<uint64_t, 16> TentativeDefinitions;
|
||||
|
||||
/// \brief Mapping from switch-case IDs in the PCH file to
|
||||
/// switch-case statements.
|
||||
std::map<unsigned, SwitchCase *> SwitchCaseStmts;
|
||||
|
|
|
@ -1713,6 +1713,13 @@ PCHReader::ReadPCHBlock(uint64_t &PreprocessorBlockOffset) {
|
|||
TotalNumMacros = Record[1];
|
||||
break;
|
||||
|
||||
case pch::TENTATIVE_DEFINITIONS:
|
||||
if (!TentativeDefinitions.empty()) {
|
||||
Error("Duplicate TENTATIVE_DEFINITIONS record in PCH file");
|
||||
return Failure;
|
||||
}
|
||||
TentativeDefinitions.swap(Record);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2523,6 +2530,13 @@ void PCHReader::InitializeSema(Sema &S) {
|
|||
SemaObj->IdResolver.AddDecl(PreloadedDecls[I]);
|
||||
}
|
||||
PreloadedDecls.clear();
|
||||
|
||||
// If there were any tentative definitions, deserialize them and add
|
||||
// them to Sema's table of tentative definitions.
|
||||
for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) {
|
||||
VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I]));
|
||||
SemaObj->TentativeDefinitions[Var->getDeclName()] = Var;
|
||||
}
|
||||
}
|
||||
|
||||
IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {
|
||||
|
|
|
@ -2024,6 +2024,15 @@ void PCHWriter::WritePCH(Sema &SemaRef) {
|
|||
getIdentifierRef(&Table.get(BuiltinNames[I]));
|
||||
}
|
||||
|
||||
// Build a record containing all of the tentative definitions in
|
||||
// this header file. Generally, this record will be empty.
|
||||
RecordData TentativeDefinitions;
|
||||
for (llvm::DenseMap<DeclarationName, VarDecl *>::iterator
|
||||
TD = SemaRef.TentativeDefinitions.begin(),
|
||||
TDEnd = SemaRef.TentativeDefinitions.end();
|
||||
TD != TDEnd; ++TD)
|
||||
AddDeclRef(TD->second, TentativeDefinitions);
|
||||
|
||||
// Write the remaining PCH contents.
|
||||
RecordData Record;
|
||||
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 3);
|
||||
|
@ -2042,8 +2051,13 @@ void PCHWriter::WritePCH(Sema &SemaRef) {
|
|||
AddTypeRef(Context.getBuiltinVaListType(), Record);
|
||||
Stream.EmitRecord(pch::SPECIAL_TYPES, Record);
|
||||
|
||||
// Write the record containing external, unnamed definitions.
|
||||
if (!ExternalDefinitions.empty())
|
||||
Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
|
||||
|
||||
// Write the record containing tentative definitions.
|
||||
if (!TentativeDefinitions.empty())
|
||||
Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions);
|
||||
|
||||
// Some simple statistics
|
||||
Record.clear();
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// Test with pch.
|
||||
// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h &&
|
||||
// RUN: clang-cc -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s &&
|
||||
|
||||
// RUN: grep "@variable = common global i32 0" %t | count 1 &&
|
||||
// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1
|
||||
|
||||
|
||||
// FIXME: tentative-defs.h expected-warning{{tentative}}
|
|
@ -0,0 +1,9 @@
|
|||
// Header for PCH test tentative-defs.c
|
||||
int variable;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int incomplete_array[];
|
Loading…
Reference in New Issue