From 699449d71eadb1499bf6a98999c2abdaa6b1294a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Tue, 27 Sep 2022 12:40:12 +0200 Subject: [PATCH] [clang][Interp][NFC] Use a SourceRange for errors This makes the error message generated by bail() a bit more pleasant to read. --- clang/lib/AST/Interp/ByteCodeGenError.h | 12 ++++++------ clang/lib/AST/Interp/Context.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeGenError.h b/clang/lib/AST/Interp/ByteCodeGenError.h index a4fa491..af464b5 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 { 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 7ce3397..a43ced4 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 &&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; } -- 2.7.4