[clang] c8341a6 - [clang][Interp][NFC] Avoid a getSource() call in the common case

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 7 00:42:55 PST 2022


Author: Timm Bäder
Date: 2022-11-07T09:42:41+01:00
New Revision: c8341a66159703de242ab8de362b59548cdda71e

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

LOG: [clang][Interp][NFC] Avoid a getSource() call in the common case

In the common (successful) case, we don't need the getSource() call, so
move it to the two if statement bodies instead.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index a5984a21efb1..b22756a80345 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -201,8 +201,8 @@ bool CheckArray(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
 
 bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
                AccessKinds AK) {
-  const auto &Src = S.Current->getSource(OpPC);
   if (Ptr.isZero()) {
+    const auto &Src = S.Current->getSource(OpPC);
 
     if (Ptr.isField())
       S.FFDiag(Src, diag::note_constexpr_null_subobject) << CSK_Field;
@@ -213,6 +213,7 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   }
 
   if (!Ptr.isLive()) {
+    const auto &Src = S.Current->getSource(OpPC);
     bool IsTemp = Ptr.isTemporary();
 
     S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;


        


More information about the cfe-commits mailing list