[clang][Interp][NFC] Use a SourceRange for errors
authorTimm Bäder <tbaeder@redhat.com>
Tue, 27 Sep 2022 10:40:12 +0000 (12:40 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Fri, 14 Oct 2022 10:46:51 +0000 (12:46 +0200)
This makes the error message generated by bail() a bit more pleasant to
read.

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

index a4fa491..af464b5 100644 (file)
@@ -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 {
index 7ce3397..a43ced4 100644 (file)
@@ -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;
 }