Skip to content

Commit

Permalink
[clang][Interp][NFC] Unify the two ReadArg() implementations
Browse files Browse the repository at this point in the history
Just use a constexpr if here instead of two different implementations.
[#
  • Loading branch information
tbaederr committed Sep 29, 2022
1 parent e8ad133 commit 7c65d57
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions clang/lib/AST/Interp/Interp.h
Expand Up @@ -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.
Expand Down

0 comments on commit 7c65d57

Please sign in to comment.