[clang][Interp][NFC] Avoid a getSource() call in the common case
authorTimm Bäder <tbaeder@redhat.com>
Mon, 31 Oct 2022 11:58:27 +0000 (12:58 +0100)
committerTimm Bäder <tbaeder@redhat.com>
Mon, 7 Nov 2022 08:42:41 +0000 (09:42 +0100)
In the common (successful) case, we don't need the getSource() call, so
move it to the two if statement bodies instead.

clang/lib/AST/Interp/Interp.cpp

index a5984a2..b22756a 100644 (file)
@@ -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;