[clang] 9c9a892 - [clang][bytecode][NFC] Avoid a `getLocation()` call in `InvalidCast` (#240748)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 10 02:10:51 PST 2026


Author: Timm Baeder
Date: 2026-11-10T11:10:42+01:00
New Revision: 9c9a892a3182c02b85b57c7515f97cd552521694

URL: https://github.com/llvm/llvm-project/commit/9c9a892a3182c02b85b57c7515f97cd552521694
DIFF: https://github.com/llvm/llvm-project/commit/9c9a892a3182c02b85b57c7515f97cd552521694.diff

LOG: [clang][bytecode][NFC] Avoid a `getLocation()` call in `InvalidCast` (#240748)

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`.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 03088ec013f147..2f4e8ee0fe59b4 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -3309,11 +3309,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;
@@ -3323,7 +3321,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;
@@ -3341,7 +3339,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;
   }


        


More information about the cfe-commits mailing list