[PATCH] D70183: Detect source location overflow due includes
Diogo N. Sampaio via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 08:39:06 PST 2019
dnsampaio updated this revision to Diff 229113.
dnsampaio marked 2 inline comments as done.
dnsampaio added a comment.
- Add ", DefaultFatal";
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70183/new/
https://reviews.llvm.org/D70183
Files:
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Basic/SourceManager.cpp
Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -577,13 +577,18 @@
SLocEntryLoaded[Index] = true;
return FileID::get(LoadedID);
}
+ unsigned FileSize = File->getSize();
+ if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
+ NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
+ // From this point, there is no sensible way to point to the current
+ // source-location and say: This include at line ### generates a too
+ // big file, as the IncludePos received is
+ Diag.Report(IncludePos, diag::err_include_too_large);
+ exit(1);
+ }
LocalSLocEntryTable.push_back(
SLocEntry::get(NextLocalOffset,
FileInfo::get(IncludePos, File, FileCharacter, Filename)));
- unsigned FileSize = File->getSize();
- assert(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
- NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset &&
- "Ran out of source locations!");
// We do a +1 here because we want a SourceLocation that means "the end of the
// file", e.g. for the "no newline at the end of the file" diagnostic.
NextLocalOffset += FileSize + 1;
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -282,6 +282,10 @@
"file '%0' modified since it was first processed">, DefaultFatal;
def err_file_too_large : Error<
"sorry, unsupported: file '%0' is too large for Clang to process">;
+def err_include_too_large : Error<
+ "sorry, this include generates a translation unit too large for"
+ " Clang to process. This may by a result from multiple"
+ " inclusions of unguarded header files.">, DefaultFatal;
def err_unsupported_bom : Error<"%0 byte order mark detected in '%1', but "
"encoding is not supported">, DefaultFatal;
def err_unable_to_rename_temp : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70183.229113.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191113/f38f0f65/attachment.bin>
More information about the cfe-commits
mailing list