[cfe-commits] r69833 - in /cfe/trunk: include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/nonvisible-external-defs.c test/PCH/nonvisible-external-defs.h
Douglas Gregor
dgregor at apple.com
Wed Apr 22 15:18:59 PDT 2009
Author: dgregor
Date: Wed Apr 22 17:18:58 2009
New Revision: 69833
URL: http://llvm.org/viewvc/llvm-project?rev=69833&view=rev
Log:
Support locally-declared external declarations in PCH files
Added:
cfe/trunk/test/PCH/nonvisible-external-defs.c
cfe/trunk/test/PCH/nonvisible-external-defs.h
Modified:
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/include/clang/Frontend/PCHReader.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69833&r1=69832&r2=69833&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 22 17:18:58 2009
@@ -156,7 +156,11 @@
STATISTICS = 9,
/// \brief Record code for the array of tentative definitions.
- TENTATIVE_DEFINITIONS = 10
+ TENTATIVE_DEFINITIONS = 10,
+
+ /// \brief Record code for the array of locally-scoped external
+ /// declarations.
+ LOCALLY_SCOPED_EXTERNAL_DECLS = 11
};
/// \brief Record types used within a source manager block.
Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=69833&r1=69832&r2=69833&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Wed Apr 22 17:18:58 2009
@@ -153,6 +153,10 @@
/// file.
llvm::SmallVector<uint64_t, 16> TentativeDefinitions;
+ /// \brief The set of locally-scoped external declarations stored in
+ /// the the PCH file.
+ llvm::SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
+
/// \brief Mapping from switch-case IDs in the PCH file to
/// switch-case statements.
std::map<unsigned, SwitchCase *> SwitchCaseStmts;
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69833&r1=69832&r2=69833&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 22 17:18:58 2009
@@ -1720,6 +1720,14 @@
}
TentativeDefinitions.swap(Record);
break;
+
+ case pch::LOCALLY_SCOPED_EXTERNAL_DECLS:
+ if (!LocallyScopedExternalDecls.empty()) {
+ Error("Duplicate LOCALLY_SCOPED_EXTERNAL_DECLS record in PCH file");
+ return Failure;
+ }
+ LocallyScopedExternalDecls.swap(Record);
+ break;
}
}
@@ -2537,6 +2545,14 @@
VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I]));
SemaObj->TentativeDefinitions[Var->getDeclName()] = Var;
}
+
+ // If there were any locally-scoped external declarations,
+ // deserialize them and add them to Sema's table of locally-scoped
+ // external declarations.
+ for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) {
+ NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I]));
+ SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D;
+ }
}
IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69833&r1=69832&r2=69833&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 22 17:18:58 2009
@@ -2033,6 +2033,16 @@
TD != TDEnd; ++TD)
AddDeclRef(TD->second, TentativeDefinitions);
+ // Build a record containing all of the locally-scoped external
+ // declarations in this header file. Generally, this record will be
+ // empty.
+ RecordData LocallyScopedExternalDecls;
+ for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
+ TD = SemaRef.LocallyScopedExternalDecls.begin(),
+ TDEnd = SemaRef.LocallyScopedExternalDecls.end();
+ TD != TDEnd; ++TD)
+ AddDeclRef(TD->second, LocallyScopedExternalDecls);
+
// Write the remaining PCH contents.
RecordData Record;
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 3);
@@ -2058,6 +2068,11 @@
// Write the record containing tentative definitions.
if (!TentativeDefinitions.empty())
Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions);
+
+ // Write the record containing locally-scoped external definitions.
+ if (!LocallyScopedExternalDecls.empty())
+ Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS,
+ LocallyScopedExternalDecls);
// Some simple statistics
Record.clear();
Added: cfe/trunk/test/PCH/nonvisible-external-defs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/nonvisible-external-defs.c?rev=69833&view=auto
==============================================================================
--- cfe/trunk/test/PCH/nonvisible-external-defs.c (added)
+++ cfe/trunk/test/PCH/nonvisible-external-defs.c Wed Apr 22 17:18:58 2009
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/nonvisible-external-defs.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/nonvisible-external-defs.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+int g(int, float); // expected-error{{conflicting types}}
+
+// expected-note{{previous declaration}}
Added: cfe/trunk/test/PCH/nonvisible-external-defs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/nonvisible-external-defs.h?rev=69833&view=auto
==============================================================================
--- cfe/trunk/test/PCH/nonvisible-external-defs.h (added)
+++ cfe/trunk/test/PCH/nonvisible-external-defs.h Wed Apr 22 17:18:58 2009
@@ -0,0 +1,11 @@
+// Helper for PCH test nonvisible-external-defs.h
+
+
+
+
+
+
+
+void f() {
+ extern int g(int, int);
+}
More information about the cfe-commits
mailing list