dexonsmith created this revision.
dexonsmith added a reviewer: JDevlieghere.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

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.


https://reviews.llvm.org/D89722

Files:
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -111,6 +111,10 @@
   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 @@
       Diag.Report(Loc, diag::err_file_too_large)
         << ContentsEntry->getName();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -145,7 +148,6 @@
       Diag.Report(Loc, diag::err_cannot_open_file)
           << ContentsEntry->getName() << BufferOrError.getError().message();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -161,7 +163,6 @@
       Diag.Report(Loc, diag::err_file_modified)
         << ContentsEntry->getName();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -174,10 +175,11 @@
   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();
 }
 


Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -111,6 +111,10 @@
   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 @@
       Diag.Report(Loc, diag::err_file_too_large)
         << ContentsEntry->getName();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -145,7 +148,6 @@
       Diag.Report(Loc, diag::err_cannot_open_file)
           << ContentsEntry->getName() << BufferOrError.getError().message();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -161,7 +163,6 @@
       Diag.Report(Loc, diag::err_file_modified)
         << ContentsEntry->getName();
 
-    IsBufferInvalid = true;
     return None;
   }
 
@@ -174,10 +175,11 @@
   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();
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D89722: So... Duncan P. N. Exon Smith via Phabricator via cfe-commits

Reply via email to