aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-19 15:28:38 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-20 21:26:37 -0400
commit4aa97e3dacf3bdf5636fbf89dd8c64f1e4648065 (patch)
treef25ef140dfacf27750e1dd72217cfaa53041631d /clang/lib/Basic/SourceManager.cpp
parentc565f09f4b0d908f51aaf4a841285f39ef93bc8c (diff)
downloadllvm-4aa97e3dacf3bdf5636fbf89dd8c64f1e4648065.zip
llvm-4aa97e3dacf3bdf5636fbf89dd8c64f1e4648065.tar.gz
llvm-4aa97e3dacf3bdf5636fbf89dd8c64f1e4648065.tar.bz2
SourceManager: Simplify early returns in ContentCache::getBufferOrNone, NFC
As suggested in the review for https://reviews.llvm.org/D89430, simplify the logic for marking the buffer as invalid in the early return paths. Differential Revision: https://reviews.llvm.org/D89722
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 84315bf..f61b4e2 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -111,6 +111,10 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
if (!ContentsEntry)
return None;
+ // Start with the assumption that the buffer is invalid to simplify early
+ // return paths.
+ IsBufferInvalid = true;
+
// Check that the file's size fits in an 'unsigned' (with room for a
// past-the-end value). This is deeply regrettable, but various parts of
// Clang (including elsewhere in this file!) use 'unsigned' to represent file
@@ -125,7 +129,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_file_too_large)
<< ContentsEntry->getName();
- IsBufferInvalid = true;
return None;
}
@@ -145,7 +148,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_cannot_open_file)
<< ContentsEntry->getName() << BufferOrError.getError().message();
- IsBufferInvalid = true;
return None;
}
@@ -161,7 +163,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_file_modified)
<< ContentsEntry->getName();
- IsBufferInvalid = true;
return None;
}
@@ -174,10 +175,11 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
if (InvalidBOM) {
Diag.Report(Loc, diag::err_unsupported_bom)
<< InvalidBOM << ContentsEntry->getName();
- IsBufferInvalid = true;
return None;
}
+ // Buffer has been validated.
+ IsBufferInvalid = false;
return Buffer->getMemBufferRef();
}