[clang] [clang][bytecode][NFC] Avoid a `getLocation()` call in `InvalidCast` (PR #240748)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 10 00:12:17 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
First, `getSource()` is better than `getLocation()` because it potentially avoids a `getExprLoc()` call, which is slow. Second, we don't need `Loc` at all for `CastKind::ReinterpretPtrToInt`.
---
Full diff: https://github.com/llvm/llvm-project/pull/240748.diff
1 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+3-5)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 5caede7d1a149d..e2eee6e665dac9 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -3310,11 +3310,9 @@ bool FinishInitGlobal(InterpState &S) {
}
bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal) {
- const SourceLocation &Loc = S.Current->getLocation(OpPC);
-
switch (Kind) {
case CastKind::Reinterpret:
- S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
+ S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
<< diag::ConstexprInvalidCastKind::Reinterpret
<< S.Current->getRange(OpPC);
return !Fatal;
@@ -3324,7 +3322,7 @@ bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal) {
assert(!Fatal);
return true;
case CastKind::ReinterpretLike:
- S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
+ S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
<< diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
<< S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
return !Fatal;
@@ -3342,7 +3340,7 @@ bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal) {
return false;
case CastKind::Dynamic:
assert(!S.getLangOpts().CPlusPlus20);
- S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
+ S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
<< diag::ConstexprInvalidCastKind::Dynamic;
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/240748
More information about the cfe-commits
mailing list