[clang] 81fb216 - [clang][Diagnostics] Provide source range to invalid casts in const expr
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 03:29:03 PDT 2023
Author: Timm Bäder
Date: 2023-07-28T12:28:45+02:00
New Revision: 81fb216245784582277663a68d535dd7f66456cb
URL: https://github.com/llvm/llvm-project/commit/81fb216245784582277663a68d535dd7f66456cb
DIFF: https://github.com/llvm/llvm-project/commit/81fb216245784582277663a68d535dd7f66456cb.diff
LOG: [clang][Diagnostics] Provide source range to invalid casts in const expr
Differential Revision: https://reviews.llvm.org/D153241
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/Interp.cpp
clang/test/Misc/constexpr-source-ranges.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 755e71f6011d6c..d9208b53e44994 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13773,7 +13773,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
case CK_PointerToIntegral: {
CCEDiag(E, diag::note_constexpr_invalid_cast)
- << 2 << Info.Ctx.getLangOpts().CPlusPlus;
+ << 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
LValue LV;
if (!EvaluatePointer(SubExpr, LV, Info))
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4d49c75799637b..b891306e6aa405 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -469,7 +469,7 @@ bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,
const SourceInfo &E = S.Current->getSource(OpPC);
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
- << 2 << S.getLangOpts().CPlusPlus;
+ << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
return false;
}
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp b/clang/test/Misc/constexpr-source-ranges.cpp
index 9ab6cc49200166..c4f83cbb0e23a4 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@ constexpr int f() {
}
// CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
More information about the cfe-commits
mailing list