[PATCH] D153241: [clang][Diagnostics] Provide source range to invalid casts in const expr
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 18 22:58:22 PDT 2023
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, shafik, hazohelet, cjdb.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153241
Files:
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/Interp.cpp
clang/test/Misc/constexpr-source-ranges.cpp
Index: clang/test/Misc/constexpr-source-ranges.cpp
===================================================================
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@
}
// 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}
Index: clang/lib/AST/Interp/Interp.cpp
===================================================================
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -524,7 +524,7 @@
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;
}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13724,7 +13724,7 @@
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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153241.532533.patch
Type: text/x-patch
Size: 1349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230619/6e8548d6/attachment-0001.bin>
More information about the cfe-commits
mailing list