/// \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
/// 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.
/// 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;
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;
}
}
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) {
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);
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();
--- /dev/null
+// 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}}
--- /dev/null
+// Header for PCH test tentative-defs.c
+int variable;
+
+
+
+
+
+
+int incomplete_array[];