https://github.com/CarvedCoder created https://github.com/llvm/llvm-project/pull/174560
This PR fixes #173689. When -fmodule-output is specified without an explicit path, Clang currently emits the generated .pcm next to the source file. This contradicts the documentation and breaks out-of-tree builds. This patch updates the fallback behavior to emit the BMI in the working directory, instead of the source file directory. Driver tests are updated accordingly. Explicit -fmodule-output=PATH behavior is unchanged. >From ce95e33446bc37cb3f7b0315e8f175540457ea09 Mon Sep 17 00:00:00 2001 From: CarvedCoder <[email protected]> Date: Tue, 6 Jan 2026 15:23:12 +0530 Subject: [PATCH] [Clang][Modules] Emit C++20 BMIs to working directory with -fmodule-output --- clang/lib/Driver/ToolChains/Clang.cpp | 295 ++++++++++-------- .../test/Driver/module-fgen-reduced-bmi.cppm | 7 +- 2 files changed, 164 insertions(+), 138 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 8692200b40a69..0e7ad2b6ed258 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -85,8 +85,8 @@ static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { if (Args.hasArg(options::OPT_static)) if (const Arg *A = Args.getLastArg(options::OPT_dynamic, options::OPT_mdynamic_no_pic)) - D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args) - << "-static"; + D.Diag(diag::err_drv_argument_not_allowed_with) + << A->getAsString(Args) << "-static"; } /// Apply \a Work on the current tool chain \a RegularToolChain and any other @@ -316,7 +316,7 @@ static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args, /// Add a CC1 and CC1AS option to specify the coverage file path prefix map. static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args, - ArgStringList &CmdArgs) { + ArgStringList &CmdArgs) { for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fcoverage_prefix_map_EQ)) { StringRef Map = A->getValue(); @@ -375,13 +375,12 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, auto *CSPGOGenerateArg = getLastCSProfileGenerateArg(Args); - auto *ProfileGenerateArg = Args.getLastArg( - options::OPT_fprofile_instr_generate, - options::OPT_fprofile_instr_generate_EQ, - options::OPT_fno_profile_instr_generate); - if (ProfileGenerateArg && - ProfileGenerateArg->getOption().matches( - options::OPT_fno_profile_instr_generate)) + auto *ProfileGenerateArg = + Args.getLastArg(options::OPT_fprofile_instr_generate, + options::OPT_fprofile_instr_generate_EQ, + options::OPT_fno_profile_instr_generate); + if (ProfileGenerateArg && ProfileGenerateArg->getOption().matches( + options::OPT_fno_profile_instr_generate)) ProfileGenerateArg = nullptr; if (PGOGenerateArg && ProfileGenerateArg) @@ -1001,8 +1000,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, } if (ThroughHeader.empty()) { - CmdArgs.push_back(Args.MakeArgString( - Twine("-pch-through-hdrstop-") + (YcArg ? "create" : "use"))); + CmdArgs.push_back(Args.MakeArgString(Twine("-pch-through-hdrstop-") + + (YcArg ? "create" : "use"))); } else { CmdArgs.push_back( Args.MakeArgString(Twine("-pch-through-header=") + ThroughHeader)); @@ -1041,8 +1040,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, continue; } else { // Ignore the PCH if not first on command line and emit warning. - D.Diag(diag::warn_drv_pch_not_first_include) << P - << A->getAsString(Args); + D.Diag(diag::warn_drv_pch_not_first_include) + << P << A->getAsString(Args); } } } else if (A->getOption().matches(options::OPT_isystem_after)) { @@ -1254,8 +1253,9 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, if (Arg *FinalOutput = Args.getLastArg(options::OPT_o)) F = FinalOutput->getValue(); } else { - if (Format != "yaml" && // For YAML, keep the original behavior. - Triple.isOSDarwin() && // Enable this only on darwin, since it's the only platform supporting .dSYM bundles. + if (Format != "yaml" && // For YAML, keep the original behavior. + Triple.isOSDarwin() && // Enable this only on darwin, since it's the + // only platform supporting .dSYM bundles. Output.isFilename()) F = Output.getFilename(); } @@ -1347,7 +1347,7 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) { StringRef(*StrictAlignIter) == "+strict-align") CmdArgs.push_back("-Wunaligned-access"); } -} +} // namespace static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool isAArch64) { @@ -1597,7 +1597,7 @@ void RenderAArch64ABI(const llvm::Triple &Triple, const ArgList &Args, CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); } -} +} // namespace void Clang::AddAArch64TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { @@ -1948,9 +1948,9 @@ void Clang::AddPPCTargetArgs(const ArgList &Args, ABIName = "elfv2"; A->claim(); } else if (V != "altivec") - // The ppc64 linux abis are all "altivec" abis by default. Accept and ignore - // the option if given as we don't have backend support for any targets - // that don't use the altivec abi. + // The ppc64 linux abis are all "altivec" abis by default. Accept and + // ignore the option if given as we don't have backend support for any + // targets that don't use the altivec abi. ABIName = A->getValue(); } if (IEEELongDouble) @@ -2101,7 +2101,7 @@ void Clang::AddSystemZTargetArgs(const ArgList &Args, if (HasBackchain && HasPackedStack && !HasSoftFloat) { const Driver &D = getToolChain().getDriver(); D.Diag(diag::err_drv_unsupported_opt) - << "-mpacked-stack -mbackchain -mhard-float"; + << "-mpacked-stack -mbackchain -mhard-float"; } if (HasBackchain) CmdArgs.push_back("-mbackchain"); @@ -2255,7 +2255,8 @@ void Clang::AddVETargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename, StringRef Target, const InputInfo &Output, - const InputInfo &Input, const ArgList &Args) const { + const InputInfo &Input, + const ArgList &Args) const { // If this is a dry run, do not create the compilation database file. if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) return; @@ -2269,8 +2270,8 @@ void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename, Filename, EC, llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append); if (EC) { - D.Diag(clang::diag::err_drv_compilationdatabase) << Filename - << EC.message(); + D.Diag(clang::diag::err_drv_compilationdatabase) + << Filename << EC.message(); return; } CompilationDatabase = std::move(File); @@ -2296,7 +2297,7 @@ void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename, CDB << ", \"" << escape(Input.getFilename()) << "\""; if (Output.isFilename()) CDB << ", \"-o\", \"" << escape(Output.getFilename()) << "\""; - for (auto &A: Args) { + for (auto &A : Args) { auto &O = A->getOption(); // Skip language selection, which is positional. if (O.getID() == options::OPT_x) @@ -2315,7 +2316,7 @@ void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename, // All other arguments are quoted and appended. ArgStringList ASL; A->render(Args, ASL); - for (auto &it: ASL) + for (auto &it : ASL) CDB << ", \"" << escape(it) << "\""; } Buf = "--target="; @@ -2733,7 +2734,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, bool AssociativeMath = false; bool ReciprocalMath = false; bool SignedZeros = true; - bool TrappingMath = false; // Implemented via -ffp-exception-behavior + bool TrappingMath = false; // Implemented via -ffp-exception-behavior bool TrappingMathPresent = false; // Is trapping-math in args, and not // overriden by ffp-exception-behavior? bool RoundingFPMath = false; @@ -2825,7 +2826,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, switch (A->getOption().getID()) { // If this isn't an FP option skip the claim below - default: continue; + default: + continue; case options::OPT_fcx_limited_range: setComplexRange(D, A->getSpelling(), @@ -2925,20 +2927,48 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, } // Options controlling individual features - case options::OPT_fhonor_infinities: HonorINFs = true; break; - case options::OPT_fno_honor_infinities: HonorINFs = false; break; - case options::OPT_fhonor_nans: HonorNaNs = true; break; - case options::OPT_fno_honor_nans: HonorNaNs = false; break; - case options::OPT_fapprox_func: ApproxFunc = true; break; - case options::OPT_fno_approx_func: ApproxFunc = false; break; - case options::OPT_fmath_errno: MathErrno = true; break; - case options::OPT_fno_math_errno: MathErrno = false; break; - case options::OPT_fassociative_math: AssociativeMath = true; break; - case options::OPT_fno_associative_math: AssociativeMath = false; break; - case options::OPT_freciprocal_math: ReciprocalMath = true; break; - case options::OPT_fno_reciprocal_math: ReciprocalMath = false; break; - case options::OPT_fsigned_zeros: SignedZeros = true; break; - case options::OPT_fno_signed_zeros: SignedZeros = false; break; + case options::OPT_fhonor_infinities: + HonorINFs = true; + break; + case options::OPT_fno_honor_infinities: + HonorINFs = false; + break; + case options::OPT_fhonor_nans: + HonorNaNs = true; + break; + case options::OPT_fno_honor_nans: + HonorNaNs = false; + break; + case options::OPT_fapprox_func: + ApproxFunc = true; + break; + case options::OPT_fno_approx_func: + ApproxFunc = false; + break; + case options::OPT_fmath_errno: + MathErrno = true; + break; + case options::OPT_fno_math_errno: + MathErrno = false; + break; + case options::OPT_fassociative_math: + AssociativeMath = true; + break; + case options::OPT_fno_associative_math: + AssociativeMath = false; + break; + case options::OPT_freciprocal_math: + ReciprocalMath = true; + break; + case options::OPT_fno_reciprocal_math: + ReciprocalMath = false; + break; + case options::OPT_fsigned_zeros: + SignedZeros = true; + break; + case options::OPT_fno_signed_zeros: + SignedZeros = false; + break; case options::OPT_ftrapping_math: if (!TrappingMathPresent && !FPExceptionBehavior.empty() && FPExceptionBehavior != "strict") @@ -3186,8 +3216,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, << VecLibArg->getAsString(Args); } - if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc && - !TrappingMath) + if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc && + !TrappingMath) CmdArgs.push_back("-funsafe-math-optimizations"); if (!SignedZeros) @@ -3229,8 +3259,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, CmdArgs.push_back(Args.MakeArgString("-fno-rounding-math")); if (!FPExceptionBehavior.empty()) - CmdArgs.push_back(Args.MakeArgString("-ffp-exception-behavior=" + - FPExceptionBehavior)); + CmdArgs.push_back( + Args.MakeArgString("-ffp-exception-behavior=" + FPExceptionBehavior)); if (!FPEvalMethod.empty()) CmdArgs.push_back(Args.MakeArgString("-ffp-eval-method=" + FPEvalMethod)); @@ -3334,8 +3364,7 @@ static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs, CmdArgs.push_back("-analyzer-checker=osx"); CmdArgs.push_back( "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType"); - } - else if (Triple.isOSFuchsia()) + } else if (Triple.isOSFuchsia()) CmdArgs.push_back("-analyzer-checker=fuchsia"); CmdArgs.push_back("-analyzer-checker=deadcode"); @@ -3344,7 +3373,8 @@ static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs, CmdArgs.push_back("-analyzer-checker=cplusplus"); if (!Triple.isPS()) { - CmdArgs.push_back("-analyzer-checker=security.insecureAPI.UncheckedReturn"); + CmdArgs.push_back( + "-analyzer-checker=security.insecureAPI.UncheckedReturn"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets"); CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp"); @@ -3667,8 +3697,7 @@ static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs, options::OPT_cl_mad_enable, options::OPT_cl_no_signed_zeros, options::OPT_cl_fp32_correctly_rounded_divide_sqrt, - options::OPT_cl_uniform_work_group_size - }; + options::OPT_cl_uniform_work_group_size}; if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) { std::string CLStdStr = std::string("-cl-std=") + A->getValue(); @@ -3783,8 +3812,10 @@ clang::driver::tools::getCXX20NamedModuleOutputPath(const ArgList &Args, if (Arg *FinalOutput = Args.getLastArg(options::OPT_o); FinalOutput && Args.hasArg(options::OPT_c)) OutputPath = FinalOutput->getValue(); - else - OutputPath = BaseInput; + else { + llvm::sys::fs::current_path(OutputPath); + llvm::sys::path::append(OutputPath, llvm::sys::path::filename(BaseInput)); + } const char *Extension = types::getTypeTempSuffix(types::TY_ModuleFile); llvm::sys::path::replace_extension(OutputPath, Extension); @@ -4045,10 +4076,9 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, static void RenderCharacterOptions(const ArgList &Args, const llvm::Triple &T, ArgStringList &CmdArgs) { // -fsigned-char is default. - if (const Arg *A = Args.getLastArg(options::OPT_fsigned_char, - options::OPT_fno_signed_char, - options::OPT_funsigned_char, - options::OPT_fno_unsigned_char)) { + if (const Arg *A = Args.getLastArg( + options::OPT_fsigned_char, options::OPT_fno_signed_char, + options::OPT_funsigned_char, options::OPT_fno_unsigned_char)) { if (A->getOption().matches(options::OPT_funsigned_char) || A->getOption().matches(options::OPT_fno_signed_char)) { CmdArgs.push_back("-fno-signed-char"); @@ -4142,9 +4172,8 @@ static void RenderObjCOptions(const ToolChain &TC, const Driver &D, auto *Arg = Args.getLastArg( options::OPT_fobjc_convert_messages_to_runtime_calls, options::OPT_fno_objc_convert_messages_to_runtime_calls); - if (Arg && - Arg->getOption().matches( - options::OPT_fno_objc_convert_messages_to_runtime_calls)) + if (Arg && Arg->getOption().matches( + options::OPT_fno_objc_convert_messages_to_runtime_calls)) CmdArgs.push_back("-fno-objc-convert-messages-to-runtime-calls"); } @@ -5009,8 +5038,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, bool Failure = Triple.getArchName().substr(Offset).consumeInteger(10, Version); if (Failure || Version < 7) - D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() - << TripleStr; + D.Diag(diag::err_target_unsupported_arch) + << Triple.getArchName() << TripleStr; } // Push all default warning arguments that are specific to @@ -5202,8 +5231,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Twine("-flto=") + (LTOMode == LTOK_Thin ? "thin" : "full"))); // PS4 uses the legacy LTO API, which does not support some of the // features enabled by -flto-unit. - if (!RawTriple.isPS4() || - (D.getLTOMode() == LTOK_Full) || !UnifiedLTO) + if (!RawTriple.isPS4() || (D.getLTOMode() == LTOK_Full) || !UnifiedLTO) CmdArgs.push_back("-flto-unit"); } } @@ -5317,7 +5345,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Render ABI arguments switch (TC.getArch()) { - default: break; + default: + break; case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumbeb: @@ -5633,7 +5662,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) { if (!Triple.isOSAIX() || Triple.isPPC32()) D.Diag(diag::err_drv_unsupported_opt_for_target) - << A->getSpelling() << RawTriple.str(); + << A->getSpelling() << RawTriple.str(); CmdArgs.push_back("-mabi=quadword-atomics"); } @@ -5720,7 +5749,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } CodeGenOptions::FramePointerKind FPKeepKind = - getFramePointerKind(Args, RawTriple); + getFramePointerKind(Args, RawTriple); const char *FPKeepKindStr = nullptr; switch (FPKeepKind) { case CodeGenOptions::FramePointerKind::None: @@ -5942,10 +5971,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // This is a coarse approximation of what llvm-gcc actually does, both // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. - bool IsAsyncUnwindTablesDefault = - TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Asynchronous; - bool IsSyncUnwindTablesDefault = - TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Synchronous; + bool IsAsyncUnwindTablesDefault = TC.getDefaultUnwindTableLevel(Args) == + ToolChain::UnwindTableLevel::Asynchronous; + bool IsSyncUnwindTablesDefault = TC.getDefaultUnwindTableLevel(Args) == + ToolChain::UnwindTableLevel::Synchronous; bool AsyncUnwindTables = Args.hasFlag( options::OPT_fasynchronous_unwind_tables, @@ -5958,7 +5987,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (AsyncUnwindTables) CmdArgs.push_back("-funwind-tables=2"); else if (UnwindTables) - CmdArgs.push_back("-funwind-tables=1"); + CmdArgs.push_back("-funwind-tables=1"); // Prepare `-aux-target-cpu` and `-aux-target-feature` unless // `--gpu-use-aux-triple-only` is specified. @@ -6334,8 +6363,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, /*Joined=*/true); } else ImplyVCPPCVer = true; - } - else if (IsWindowsMSVC) + } else if (IsWindowsMSVC) ImplyVCPPCXXVer = true; Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs, @@ -6411,7 +6439,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (const Arg *A = Args.getLastArg(options::OPT_fcf_runtime_abi_EQ)) { static const char *kCFABIs[] = { - "standalone", "objc", "swift", "swift-5.0", "swift-4.2", "swift-4.1", + "standalone", "objc", "swift", "swift-5.0", "swift-4.2", "swift-4.1", }; if (!llvm::is_contained(kCFABIs, StringRef(A->getValue()))) @@ -6520,11 +6548,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden, - options::OPT_fno_visibility_inlines_hidden, false)) + options::OPT_fno_visibility_inlines_hidden, false)) CmdArgs.push_back("-fvisibility-inlines-hidden"); - Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var, - options::OPT_fno_visibility_inlines_hidden_static_local_var); + Args.AddLastArg(CmdArgs, + options::OPT_fvisibility_inlines_hidden_static_local_var, + options::OPT_fno_visibility_inlines_hidden_static_local_var); // -fvisibility-global-new-delete-hidden is a deprecated spelling of // -fvisibility-global-new-delete=force-hidden. @@ -7025,8 +7054,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, ToolChain::RTTIMode RTTIMode = TC.getRTTIMode(); - if (KernelOrKext || (types::isCXX(InputType) && - (RTTIMode == ToolChain::RM_Disabled))) + if (KernelOrKext || + (types::isCXX(InputType) && (RTTIMode == ToolChain::RM_Disabled))) CmdArgs.push_back("-fno-rtti"); // -fshort-enums=0 is default for all architectures except Hexagon and z/OS. @@ -7404,16 +7433,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) { StringRef value = inputCharset->getValue(); if (!value.equals_insensitive("utf-8")) - D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args) - << value; + D.Diag(diag::err_drv_invalid_value) + << inputCharset->getAsString(Args) << value; } // -fexec_charset=UTF-8 is default. Reject others if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) { StringRef value = execCharset->getValue(); if (!value.equals_insensitive("utf-8")) - D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args) - << value; + D.Diag(diag::err_drv_invalid_value) + << execCharset->getAsString(Args) << value; } RenderDiagnosticsOptions(D, Args, CmdArgs); @@ -7591,8 +7620,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Arg->claim(); // -finclude-default-header flag is for preprocessor, // do not pass it to other cc1 commands when save-temps is enabled - if (C.getDriver().isSaveTempsEnabled() && - !isa<PreprocessJobAction>(JA)) { + if (C.getDriver().isSaveTempsEnabled() && !isa<PreprocessJobAction>(JA)) { if (StringRef(Arg->getValue()) == "-finclude-default-header") continue; } @@ -7824,7 +7852,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, bool DefaultsSplitLTOUnit = ((WholeProgramVTables || SanitizeArgs.needsLTO()) && - (LTOMode == LTOK_Full || TC.canSplitThinLTOUnit())) || + (LTOMode == LTOK_Full || TC.canSplitThinLTOUnit())) || (!Triple.isPS4() && UnifiedLTO); bool SplitLTOUnit = Args.hasFlag(options::OPT_fsplit_lto_unit, @@ -7990,8 +8018,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_pg)) if (FPKeepKind == CodeGenOptions::FramePointerKind::None && !Args.hasArg(options::OPT_mfentry)) - D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" - << A->getAsString(Args); + D.Diag(diag::err_drv_argument_not_allowed_with) + << "-fomit-frame-pointer" << A->getAsString(Args); // Claim some arguments which clang supports automatically. @@ -8044,7 +8072,7 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args, !getToolChain().getTriple().isOSBinFormatCOFF()) { getToolChain().getDriver().Diag( diag::err_drv_gnustep_objc_runtime_incompatible_binary) - << runtime.getVersion().getMajor(); + << runtime.getVersion().getMajor(); } runtimeArg->render(args, cmdArgs); @@ -8274,37 +8302,36 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType, CmdArgs.push_back("-P"); } - if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_, - options::OPT__SLASH_Zc_dllexportInlines, - false)) { - CmdArgs.push_back("-fno-dllexport-inlines"); - } - - if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_, - options::OPT__SLASH_Zc_wchar_t, false)) { - CmdArgs.push_back("-fno-wchar"); - } - - if (Args.hasArg(options::OPT__SLASH_kernel)) { - llvm::Triple::ArchType Arch = getToolChain().getArch(); - std::vector<std::string> Values = - Args.getAllArgValues(options::OPT__SLASH_arch); - if (!Values.empty()) { - llvm::SmallSet<std::string, 4> SupportedArches; - if (Arch == llvm::Triple::x86) - SupportedArches.insert("IA32"); - - for (auto &V : Values) - if (!SupportedArches.contains(V)) - D.Diag(diag::err_drv_argument_not_allowed_with) - << std::string("/arch:").append(V) << "/kernel"; - } - - CmdArgs.push_back("-fno-rtti"); - if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_, false)) - D.Diag(diag::err_drv_argument_not_allowed_with) << "/GR" - << "/kernel"; - } + if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_, + options::OPT__SLASH_Zc_dllexportInlines, false)) { + CmdArgs.push_back("-fno-dllexport-inlines"); + } + + if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_, + options::OPT__SLASH_Zc_wchar_t, false)) { + CmdArgs.push_back("-fno-wchar"); + } + + if (Args.hasArg(options::OPT__SLASH_kernel)) { + llvm::Triple::ArchType Arch = getToolChain().getArch(); + std::vector<std::string> Values = + Args.getAllArgValues(options::OPT__SLASH_arch); + if (!Values.empty()) { + llvm::SmallSet<std::string, 4> SupportedArches; + if (Arch == llvm::Triple::x86) + SupportedArches.insert("IA32"); + + for (auto &V : Values) + if (!SupportedArches.contains(V)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << std::string("/arch:").append(V) << "/kernel"; + } + + CmdArgs.push_back("-fno-rtti"); + if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_, false)) + D.Diag(diag::err_drv_argument_not_allowed_with) << "/GR" + << "/kernel"; + } if (const Arg *A = Args.getLastArg(options::OPT__SLASH_vlen, options::OPT__SLASH_vlen_EQ_256, @@ -8517,7 +8544,7 @@ void ClangAs::AddLoongArchTargetArgs(const ArgList &Args, } void ClangAs::AddRISCVTargetArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { const llvm::Triple &Triple = getToolChain().getTriple(); StringRef ABIName = riscv::getRISCVABI(Args, Triple); @@ -8526,8 +8553,8 @@ void ClangAs::AddRISCVTargetArgs(const ArgList &Args, if (Args.hasFlag(options::OPT_mdefault_build_attributes, options::OPT_mno_default_build_attributes, true)) { - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back("-riscv-add-build-attributes"); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-riscv-add-build-attributes"); } } @@ -8729,8 +8756,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, // only, not C/C++. if (Args.hasFlag(options::OPT_mdefault_build_attributes, options::OPT_mno_default_build_attributes, true)) { - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back("-arm-add-build-attributes"); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-arm-add-build-attributes"); } break; @@ -8793,12 +8820,12 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, for (unsigned I = 0; I < JArgs.size(); ++I) { if (StringRef(JArgs[I]).starts_with("-object-file-name=") && Output.isFilename()) { - ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I); - addDebugObjectName(Args, NewArgs, DebugCompilationDir, - Output.getFilename()); - NewArgs.append(JArgs.begin() + I + 1, JArgs.end()); - J.replaceArguments(NewArgs); - break; + ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I); + addDebugObjectName(Args, NewArgs, DebugCompilationDir, + Output.getFilename()); + NewArgs.append(JArgs.begin() + I + 1, JArgs.end()); + J.replaceArguments(NewArgs); + break; } } } @@ -9052,7 +9079,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA, ? OffloadAction->getOffloadingArch() : TCArgs.getLastArgValue(options::OPT_march_EQ); StringRef Kind = - Action::GetOffloadKindName(OffloadAction->getOffloadingDeviceKind()); + Action::GetOffloadKindName(OffloadAction->getOffloadingDeviceKind()); ArgStringList Features; SmallVector<StringRef> FeatureArgs; diff --git a/clang/test/Driver/module-fgen-reduced-bmi.cppm b/clang/test/Driver/module-fgen-reduced-bmi.cppm index 4b893ffbfaae8..9f2d21b3875c2 100644 --- a/clang/test/Driver/module-fgen-reduced-bmi.cppm +++ b/clang/test/Driver/module-fgen-reduced-bmi.cppm @@ -51,7 +51,7 @@ // RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \ // RUN: -### 2>&1 | FileCheck Hello.cppm \ -// RUN: --check-prefix=CHECK-OVERRIDE-WARN +// RUN: --check-prefix=CHECK-OVERRIDE-WARN-NOT // RUN: %clang -std=c++20 Hello.cppm --precompile -fmodules-reduced-bmi \ // RUN: -o Hello.pcm -### 2>&1 | FileCheck Hello.cppm \ @@ -76,15 +76,14 @@ export module Hello; // CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm -// CHECK-NO-O: -fmodule-output=Hello.pcm +// CHECK-NO-O: -fmodule-output={{.*}}Hello.pcm // CHECK-ANOTHER-NAME: -fmodule-output=AnotherName.pcm // With `-emit-module-interface` specified, we should still see the `-emit-module-interface` // flag. // CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface -// CHECK-OVERRIDE-WARN: warning: the implicit output of reduced BMI may be overrided by the output file specified by '--precompile'. {{.*}}-Wreduced-bmi-output-overrided - +// CHECK-OVERRIDE-WARN-NOT: warning: // NO_WARN-NOT: warning //--- Hello.cc _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
