diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-06-06 17:25:21 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-06-06 17:25:21 +0000 |
commit | d73ef135ba029db59c0b5649e6117845d9e39600 (patch) | |
tree | 4e353271c446576ebfa70b18525f90ad68fa372c /include/clang/Basic/SourceManager.h | |
parent | a08e7bc74b5635995fc50009f240dd3feb1999e2 (diff) |
Add pedantic warning -Wempty-translation-unit (C11 6.9p1).
In standard C since C89, a 'translation-unit' is syntactically defined to have
at least one "external-declaration", which is either a decl or a function
definition. In Clang the latter gives us a declaration as well.
The tricky bit about this warning is that our predefines can contain external
declarations (__builtin_va_list and the 128-bit integer types). Therefore our
AST parser now makes sure we have at least one declaration that doesn't come
from the predefines buffer.
Also, remove bogus warning about empty source files. This doesn't catch source
files that only contain comments, and never fired anyway because of our
predefines.
PR12665 and <rdar://problem/9165548>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158085 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 3164f874f1..f7fb1f5231 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -584,6 +584,9 @@ class SourceManager : public RefCountedBase<SourceManager> { /// \brief The file ID for the precompiled preamble there is one. FileID PreambleFileID; + /// \brief The file ID for the preprocessor's predefines. + FileID PredefinesFileID; + // Statistics for -print-stats. mutable unsigned NumLinearScans, NumBinaryProbes; @@ -628,6 +631,14 @@ public: MainFileID = createFileIDForMemBuffer(Buffer); return MainFileID; } + + /// \brief Create the FileID for a memory buffer that contains the + /// preprocessor's predefines. + FileID createPredefinesFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) { + assert(PredefinesFileID.isInvalid() && "PredefinesFileID already set!"); + PredefinesFileID = createFileIDForMemBuffer(Buffer); + return PredefinesFileID; + } //===--------------------------------------------------------------------===// // MainFileID creation and querying methods. @@ -636,6 +647,9 @@ public: /// getMainFileID - Returns the FileID of the main source file. FileID getMainFileID() const { return MainFileID; } + /// \brief Returns the FileID of the preprocessor predefines buffer. + FileID getPredefinesFileID() const { return PredefinesFileID; } + /// createMainFileID - Create the FileID for the main source file. FileID createMainFileID(const FileEntry *SourceFile, SrcMgr::CharacteristicKind Kind = SrcMgr::C_User) { @@ -1113,6 +1127,12 @@ public: return getFileID(Loc) == getMainFileID(); } + /// isFromPredefines - Returns true if the provided SourceLocation is + /// within the processor's predefines buffer. + bool isFromPredefines(SourceLocation Loc) const { + return getFileID(Loc) == getPredefinesFileID(); + } + /// isInSystemHeader - Returns if a SourceLocation is in a system header. bool isInSystemHeader(SourceLocation Loc) const { return getFileCharacteristic(Loc) != SrcMgr::C_User; |