[clang] 7c65d57 - [clang][Interp][NFC] Unify the two ReadArg() implementations
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 29 03:51:45 PDT 2022
Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: 7c65d57af0ef20ce28ca9c1efae8e3214d57268d
URL: https://github.com/llvm/llvm-project/commit/7c65d57af0ef20ce28ca9c1efae8e3214d57268d
DIFF: https://github.com/llvm/llvm-project/commit/7c65d57af0ef20ce28ca9c1efae8e3214d57268d.diff
LOG: [clang][Interp][NFC] Unify the two ReadArg() implementations
Just use a constexpr if here instead of two different implementations.
[#
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 c8df624dfa23..0df7ead28cd3 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -993,17 +993,13 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) {
// Read opcode arguments
//===----------------------------------------------------------------------===//
-template <typename T>
-inline std::enable_if_t<!std::is_pointer<T>::value, T> ReadArg(InterpState &S,
- CodePtr &OpPC) {
- return OpPC.read<T>();
-}
-
-template <typename T>
-inline std::enable_if_t<std::is_pointer<T>::value, T> ReadArg(InterpState &S,
- CodePtr &OpPC) {
- uint32_t ID = OpPC.read<uint32_t>();
- return reinterpret_cast<T>(S.P.getNativePointer(ID));
+template <typename T> inline T ReadArg(InterpState &S, CodePtr &OpPC) {
+ if constexpr (std::is_pointer<T>::value) {
+ uint32_t ID = OpPC.read<uint32_t>();
+ return reinterpret_cast<T>(S.P.getNativePointer(ID));
+ } else {
+ return OpPC.read<T>();
+ }
}
/// Interpreter entry point.
More information about the cfe-commits
mailing list