4343#include " llvm/Support/Error.h"
4444#include " llvm/Support/FileSystem.h"
4545#include " llvm/Support/TargetSelect.h"
46+ #include " llvm/TargetParser/Triple.h"
4647
4748#include " llvm/IR/LLVMContext.h"
4849#include " llvm/IR/Module.h"
@@ -407,24 +408,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
407408// / \return
408409// / A string representing target ABI for the current architecture.
409410static std::string GetClangTargetABI (const ArchSpec &target_arch) {
410- std::string abi;
411-
412411 if (target_arch.IsMIPS ()) {
413412 switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask) {
414413 case ArchSpec::eMIPSABI_N64:
415- abi = " n64" ;
416- break ;
414+ return " n64" ;
417415 case ArchSpec::eMIPSABI_N32:
418- abi = " n32" ;
419- break ;
416+ return " n32" ;
420417 case ArchSpec::eMIPSABI_O32:
421- abi = " o32" ;
422- break ;
418+ return " o32" ;
423419 default :
424- break ;
420+ return {} ;
425421 }
426422 }
427- return abi;
423+
424+ if (target_arch.GetTriple ().isRISCV64 ()) {
425+ switch (target_arch.GetFlags () & ArchSpec::eRISCV_float_abi_mask) {
426+ case ArchSpec::eRISCV_float_abi_soft:
427+ return " lp64" ;
428+ case ArchSpec::eRISCV_float_abi_single:
429+ return " lp64f" ;
430+ case ArchSpec::eRISCV_float_abi_double:
431+ return " lp64d" ;
432+ case ArchSpec::eRISCV_float_abi_quad:
433+ return " lp64q" ;
434+ default :
435+ return {};
436+ }
437+ }
438+
439+ if (target_arch.GetTriple ().isRISCV32 ()) {
440+ switch (target_arch.GetFlags () & ArchSpec::eRISCV_float_abi_mask) {
441+ case ArchSpec::eRISCV_float_abi_soft:
442+ return " ilp32" ;
443+ case ArchSpec::eRISCV_float_abi_single:
444+ return " ilp32f" ;
445+ case ArchSpec::eRISCV_float_abi_double:
446+ return " ilp32d" ;
447+ case ArchSpec::eRISCV_float_abi_soft | ArchSpec::eRISCV_rve:
448+ return " ilp32e" ;
449+ default :
450+ return {};
451+ }
452+ }
453+
454+ return {};
428455}
429456
430457static void SetupTargetOpts (CompilerInstance &compiler,
@@ -471,6 +498,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
471498 // Set the target ABI
472499 if (std::string abi = GetClangTargetABI (target_arch); !abi.empty ())
473500 compiler.getTargetOpts ().ABI = std::move (abi);
501+
502+ if ((target_machine == llvm::Triple::riscv64 &&
503+ compiler.getTargetOpts ().ABI == " lp64f" ) ||
504+ (target_machine == llvm::Triple::riscv32 &&
505+ compiler.getTargetOpts ().ABI == " ilp32f" ))
506+ compiler.getTargetOpts ().FeaturesAsWritten .emplace_back (" +f" );
507+
508+ if ((target_machine == llvm::Triple::riscv64 &&
509+ compiler.getTargetOpts ().ABI == " lp64d" ) ||
510+ (target_machine == llvm::Triple::riscv32 &&
511+ compiler.getTargetOpts ().ABI == " ilp32d" ))
512+ compiler.getTargetOpts ().FeaturesAsWritten .emplace_back (" +d" );
474513}
475514
476515static void SetupLangOpts (CompilerInstance &compiler,
@@ -722,7 +761,7 @@ ClangExpressionParser::ClangExpressionParser(
722761 m_compiler->getCodeGenOpts ().EmitDeclMetadata = true ;
723762 m_compiler->getCodeGenOpts ().InstrumentFunctions = false ;
724763 m_compiler->getCodeGenOpts ().setFramePointer (
725- CodeGenOptions::FramePointerKind::All);
764+ CodeGenOptions::FramePointerKind::All);
726765 if (generate_debug_info)
727766 m_compiler->getCodeGenOpts ().setDebugInfo (codegenoptions::FullDebugInfo);
728767 else
@@ -736,7 +775,7 @@ ClangExpressionParser::ClangExpressionParser(
736775 // FIXME: We shouldn't need to do this, the target should be immutable once
737776 // created. This complexity should be lifted elsewhere.
738777 m_compiler->getTarget ().adjust (m_compiler->getDiagnostics (),
739- m_compiler->getLangOpts ());
778+ m_compiler->getLangOpts ());
740779
741780 // 5. Set up the diagnostic buffer for reporting errors
742781
@@ -1156,8 +1195,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
11561195 if (auto fileEntry = m_compiler->getFileManager ().getOptionalFileRef (
11571196 result_path)) {
11581197 source_mgr.setMainFileID (source_mgr.createFileID (
1159- *fileEntry,
1160- SourceLocation (), SrcMgr::C_User));
1198+ *fileEntry, SourceLocation (), SrcMgr::C_User));
11611199 created_main_file = true ;
11621200 }
11631201 }
@@ -1504,7 +1542,8 @@ lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
15041542
15051543 DiagnosticManager install_diags;
15061544 if (Error Err = dynamic_checkers->Install (install_diags, exe_ctx)) {
1507- std::string ErrMsg = " couldn't install checkers: " + toString (std::move (Err));
1545+ std::string ErrMsg =
1546+ " couldn't install checkers: " + toString (std::move (Err));
15081547 if (install_diags.Diagnostics ().size ())
15091548 ErrMsg = ErrMsg + " \n " + install_diags.GetString ().c_str ();
15101549 err = Status (ErrMsg);
0 commit comments