diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 9b056ea73a77fb..39f0e6269cd0f0 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -44,6 +44,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/TargetParser/Triple.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -442,24 +443,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) { /// \return /// A string representing target ABI for the current architecture. static std::string GetClangTargetABI(const ArchSpec &target_arch) { - std::string abi; - if (target_arch.IsMIPS()) { switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) { case ArchSpec::eMIPSABI_N64: - abi = "n64"; - break; + return "n64"; case ArchSpec::eMIPSABI_N32: - abi = "n32"; - break; + return "n32"; case ArchSpec::eMIPSABI_O32: - abi = "o32"; - break; + return "o32"; default: - break; + return {}; } } - return abi; + + if (target_arch.GetTriple().isRISCV64()) { + switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) { + case ArchSpec::eRISCV_float_abi_soft: + return "lp64"; + case ArchSpec::eRISCV_float_abi_single: + return "lp64f"; + case ArchSpec::eRISCV_float_abi_double: + return "lp64d"; + case ArchSpec::eRISCV_float_abi_quad: + return "lp64q"; + default: + return {}; + } + } + + if (target_arch.GetTriple().isRISCV32()) { + switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) { + case ArchSpec::eRISCV_float_abi_soft: + return "ilp32"; + case ArchSpec::eRISCV_float_abi_single: + return "ilp32f"; + case ArchSpec::eRISCV_float_abi_double: + return "ilp32d"; + case ArchSpec::eRISCV_float_abi_soft | ArchSpec::eRISCV_rve: + return "ilp32e"; + default: + return {}; + } + } + + return {}; } static void SetupTargetOpts(CompilerInstance &compiler, @@ -506,6 +533,18 @@ static void SetupTargetOpts(CompilerInstance &compiler, // Set the target ABI if (std::string abi = GetClangTargetABI(target_arch); !abi.empty()) compiler.getTargetOpts().ABI = std::move(abi); + + if ((target_machine == llvm::Triple::riscv64 && + compiler.getTargetOpts().ABI == "lp64f") || + (target_machine == llvm::Triple::riscv32 && + compiler.getTargetOpts().ABI == "ilp32f")) + compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+f"); + + if ((target_machine == llvm::Triple::riscv64 && + compiler.getTargetOpts().ABI == "lp64d") || + (target_machine == llvm::Triple::riscv32 && + compiler.getTargetOpts().ABI == "ilp32d")) + compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+d"); } static void SetupLangOpts(CompilerInstance &compiler, @@ -757,7 +796,7 @@ ClangExpressionParser::ClangExpressionParser( m_compiler->getCodeGenOpts().EmitDeclMetadata = true; m_compiler->getCodeGenOpts().InstrumentFunctions = false; m_compiler->getCodeGenOpts().setFramePointer( - CodeGenOptions::FramePointerKind::All); + CodeGenOptions::FramePointerKind::All); if (generate_debug_info) m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo); else @@ -771,7 +810,7 @@ ClangExpressionParser::ClangExpressionParser( // FIXME: We shouldn't need to do this, the target should be immutable once // created. This complexity should be lifted elsewhere. m_compiler->getTarget().adjust(m_compiler->getDiagnostics(), - m_compiler->getLangOpts()); + m_compiler->getLangOpts()); // 5. Set up the diagnostic buffer for reporting errors auto diag_mgr = new ClangDiagnosticManagerAdapter( @@ -1191,8 +1230,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager, if (auto fileEntry = m_compiler->getFileManager().getOptionalFileRef( result_path)) { source_mgr.setMainFileID(source_mgr.createFileID( - *fileEntry, - SourceLocation(), SrcMgr::C_User)); + *fileEntry, SourceLocation(), SrcMgr::C_User)); created_main_file = true; } }