[clang] d128a03 - [clang][Interp][NFC] Use constexpr if in OffsetHelper

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 16 00:56:48 PST 2022


Author: Timm Bäder
Date: 2022-11-16T09:56:29+01:00
New Revision: d128a03ff3b1d3e48fae41a10e790faf3a775d35

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

LOG: [clang][Interp][NFC] Use constexpr if in OffsetHelper

Add here is a template parameter, so we can do this.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index a90e1246311d8..002571e731371 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1056,7 +1056,12 @@ template <class T, bool Add> bool OffsetHelper(InterpState &S, CodePtr OpPC) {
   // Offset is valid - compute it on unsigned.
   int64_t WideIndex = static_cast<int64_t>(Index);
   int64_t WideOffset = static_cast<int64_t>(Offset);
-  int64_t Result = Add ? (WideIndex + WideOffset) : (WideIndex - WideOffset);
+  int64_t Result;
+  if constexpr (Add)
+    Result = WideIndex + WideOffset;
+  else
+    Result = WideIndex - WideOffset;
+
   S.Stk.push<Pointer>(Ptr.atIndex(static_cast<unsigned>(Result)));
   return true;
 }


        


More information about the cfe-commits mailing list