From 819914beca7bd328df331cb9026b63a64251c2c2 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Wed, 17 Jan 2024 14:05:58 +0000 Subject: [PATCH] tbv2: fix thrift isset with ClangTypeParser Some of the logic that makes Thrift isset work for TreeBuilder-v2 in DrgnParser (JIT OIL) wasn't ported to ClangTypeParser meaning it doesn't work in Ahead-of-Time (AoT) OIL. Add the template parameter name reconstruction for enum values to ClangTypeParser. Test plan: - Tested with Thrift isset enabled on an internal type. Doesn't build before, does build after. --- oi/type_graph/ClangTypeParser.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/oi/type_graph/ClangTypeParser.cpp b/oi/type_graph/ClangTypeParser.cpp index cb33377..40f3a69 100644 --- a/oi/type_graph/ClangTypeParser.cpp +++ b/oi/type_graph/ClangTypeParser.cpp @@ -235,9 +235,29 @@ std::optional ClangTypeParser::enumerateTemplateParam( } case clang::TemplateArgument::Integral: { auto& ty = enumerateType(*p.getIntegralType()); - llvm::SmallString<32> val; - p.getAsIntegral().toString(val); - return TemplateParam{ty, std::string(val)}; + + std::string value; + if (const auto* e = dynamic_cast(&ty)) { + const auto& eTy = + llvm::cast(*p.getIntegralType()); + for (const auto* enumerator : eTy.getDecl()->enumerators()) { + if (enumerator->getInitVal() == p.getAsIntegral()) { + value = e->inputName(); + value += "::"; + value += enumerator->getName(); + break; + } + } + if (value.empty()) { + throw std::runtime_error("unable to find enum name for value"); + } + } else { + llvm::SmallString<32> val; + p.getAsIntegral().toString(val); + value = std::string{val}; + } + + return TemplateParam{ty, value}; } case clang::TemplateArgument::Template: { return enumerateTemplateTemplateParam(p.getAsTemplate());