[clang][Interp][NFC] Unifty ReadArg() impl in Disasm.cpp
authorTimm Bäder <tbaeder@redhat.com>
Fri, 23 Sep 2022 10:40:44 +0000 (12:40 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 29 Sep 2022 10:50:57 +0000 (12:50 +0200)
We can use another if constexpr here to make this shorter and easier to
understand.

clang/lib/AST/Interp/Disasm.cpp

index 82cc849..67cc248 100644 (file)
 using namespace clang;
 using namespace clang::interp;
 
-template <typename T>
-inline std::enable_if_t<!std::is_pointer<T>::value, T> ReadArg(Program &P,
-                                                               CodePtr &OpPC) {
-  return OpPC.read<T>();
-}
-
-template <typename T>
-inline std::enable_if_t<std::is_pointer<T>::value, T> ReadArg(Program &P,
-                                                              CodePtr &OpPC) {
-  uint32_t ID = OpPC.read<uint32_t>();
-  return reinterpret_cast<T>(P.getNativePointer(ID));
+template <typename T> inline T ReadArg(Program &P, CodePtr &OpPC) {
+  if constexpr (std::is_pointer<T>::value) {
+    uint32_t ID = OpPC.read<uint32_t>();
+    return reinterpret_cast<T>(P.getNativePointer(ID));
+  } else {
+    return OpPC.read<T>();
+  }
 }
 
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }