[clang] 699449d - [clang][Interp][NFC] Use a SourceRange for errors

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 14 03:47:25 PDT 2022


Author: Timm Bäder
Date: 2022-10-14T12:46:51+02:00
New Revision: 699449d71eadb1499bf6a98999c2abdaa6b1294a

URL: https://github.com/llvm/llvm-project/commit/699449d71eadb1499bf6a98999c2abdaa6b1294a
DIFF: https://github.com/llvm/llvm-project/commit/699449d71eadb1499bf6a98999c2abdaa6b1294a.diff

LOG: [clang][Interp][NFC] Use a SourceRange for errors

This makes the error message generated by bail() a bit more pleasant to
read.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeGenError.h
    clang/lib/AST/Interp/Context.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeGenError.h b/clang/lib/AST/Interp/ByteCodeGenError.h
index a4fa4917705d..af464b5ed4ab 100644
--- a/clang/lib/AST/Interp/ByteCodeGenError.h
+++ b/clang/lib/AST/Interp/ByteCodeGenError.h
@@ -20,19 +20,19 @@ namespace interp {
 /// Error thrown by the compiler.
 struct ByteCodeGenError : public llvm::ErrorInfo<ByteCodeGenError> {
 public:
-  ByteCodeGenError(SourceLocation Loc) : Loc(Loc) {}
-  ByteCodeGenError(const Stmt *S) : ByteCodeGenError(S->getBeginLoc()) {}
-  ByteCodeGenError(const Decl *D) : ByteCodeGenError(D->getBeginLoc()) {}
+  ByteCodeGenError(SourceRange Range) : Range(Range) {}
+  ByteCodeGenError(const Stmt *S) : ByteCodeGenError(S->getSourceRange()) {}
+  ByteCodeGenError(const Decl *D) : ByteCodeGenError(D->getSourceRange()) {}
 
   void log(raw_ostream &OS) const override { OS << "unimplemented feature"; }
 
-  const SourceLocation &getLoc() const { return Loc; }
+  const SourceRange &getRange() const { return Range; }
 
   static char ID;
 
 private:
-  // Start of the item where the error occurred.
-  SourceLocation Loc;
+  // Range of the item where the error occurred.
+  SourceRange Range;
 
   // Users are not expected to use error_code.
   std::error_code convertToErrorCode() const override {

diff  --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 7ce3397e6a4f..a43ced4f856c 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -33,7 +33,9 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
       Func = *R;
     } else {
       handleAllErrors(R.takeError(), [&Parent](ByteCodeGenError &Err) {
-        Parent.FFDiag(Err.getLoc(), diag::err_experimental_clang_interp_failed);
+        Parent.FFDiag(Err.getRange().getBegin(),
+                      diag::err_experimental_clang_interp_failed)
+            << Err.getRange();
       });
       return false;
     }
@@ -119,7 +121,9 @@ bool Context::Check(State &Parent, llvm::Expected<bool> &&Flag) {
   if (Flag)
     return *Flag;
   handleAllErrors(Flag.takeError(), [&Parent](ByteCodeGenError &Err) {
-    Parent.FFDiag(Err.getLoc(), diag::err_experimental_clang_interp_failed);
+    Parent.FFDiag(Err.getRange().getBegin(),
+                  diag::err_experimental_clang_interp_failed)
+        << Err.getRange();
   });
   return false;
 }


        


More information about the cfe-commits mailing list