From: Fangrui Song Date: Tue, 8 Nov 2022 22:39:09 +0000 (-0800) Subject: [Driver] Refactor err_drv_unsupported_option_argument call sites to use llvm::opt... X-Git-Tag: upstream/17.0.6~28175 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c2c62282fca2f3dbfa338427aa97f702e67f86b;p=platform%2Fupstream%2Fllvm.git [Driver] Refactor err_drv_unsupported_option_argument call sites to use llvm::opt::Arg::getSpelling For `-foo=bar`, getSpelling return `-foo=` which is exactly what we need from the diagnostic. Drop `-` from the err_drv_unsupported_option_argument template. This change makes `--` long option diagnostics more convenient. Reviewed By: lenary Differential Revision: https://reviews.llvm.org/D137659 --- diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 44c277b..12c246b 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -19,7 +19,7 @@ def err_drv_unsupported_opt_for_target : Error< def err_drv_unsupported_opt_for_language_mode : Error< "unsupported option '%0' for language mode '%1'">; def err_drv_unsupported_option_argument : Error< - "unsupported argument '%1' to option '-%0'">; + "unsupported argument '%1' to option '%0'">; def err_drv_unknown_stdin_type : Error< "-E or -x required when input is from standard input">; def err_drv_unknown_stdin_type_clang_cl : Error< diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 27e15b9..a45c9e7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -703,7 +703,7 @@ static driver::LTOKind parseLTOMode(Driver &D, const llvm::opt::ArgList &Args, if (LTOMode == LTOK_Unknown) { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getSpelling() << A->getValue(); return LTOK_None; } return LTOMode; @@ -735,7 +735,7 @@ Driver::OpenMPRuntimeKind Driver::getOpenMPRuntime(const ArgList &Args) const { if (RT == OMPRT_Unknown) { if (A) Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getSpelling() << A->getValue(); else // FIXME: We could use a nicer diagnostic here. Diag(diag::err_drv_unsupported_opt) << "-fopenmp"; diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index a710081..e88cfae 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -249,7 +249,7 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D, SanitizerSet S; S.Mask = InvalidValues; D.Diag(diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << toString(S); + << Arg->getSpelling() << toString(S); } TrappingKinds |= expandSanitizerGroups(Add) & ~TrapRemove; } else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) { @@ -604,7 +604,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, SetToDiagnose.Mask |= KindsToDiagnose; if (DiagnoseErrors) D.Diag(diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << toString(SetToDiagnose); + << Arg->getSpelling() << toString(SetToDiagnose); DiagnosedUnrecoverableKinds |= KindsToDiagnose; } RecoverableKinds |= expandSanitizerGroups(Add); @@ -619,7 +619,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, SetToDiagnose.Mask |= KindsToDiagnose; if (DiagnoseErrors) D.Diag(diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << toString(SetToDiagnose); + << Arg->getSpelling() << toString(SetToDiagnose); DiagnosedAlwaysRecoverableKinds |= KindsToDiagnose; } RecoverableKinds &= ~expandSanitizerGroups(Remove); @@ -951,7 +951,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, auto parsedAsanDtorKind = AsanDtorKindFromString(Arg->getValue()); if (parsedAsanDtorKind == llvm::AsanDtorKind::Invalid && DiagnoseErrors) { TC.getDriver().Diag(clang::diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << Arg->getValue(); + << Arg->getSpelling() << Arg->getValue(); } AsanDtorKind = parsedAsanDtorKind; } @@ -964,7 +964,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, llvm::AsanDetectStackUseAfterReturnMode::Invalid && DiagnoseErrors) { TC.getDriver().Diag(clang::diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << Arg->getValue(); + << Arg->getSpelling() << Arg->getValue(); } AsanUseAfterReturn = parsedAsanUseAfterReturn; } @@ -1346,7 +1346,7 @@ SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, Kinds |= Kind; else if (DiagnoseErrors) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } return Kinds; } @@ -1381,7 +1381,7 @@ int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A, .Default(0); if (F == 0 && DiagnoseErrors) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; Features |= F; } return Features; @@ -1403,7 +1403,7 @@ int parseBinaryMetadataFeatures(const Driver &D, const llvm::opt::Arg *A, .Default(0); if (F == 0 && DiagnoseErrors) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; Features |= F; } return Features; diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 514db4c..87bb7c5 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -274,9 +274,9 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, // If "-Wa,-march=" is used, 'WaMArch' will contain the argument's value, // while 'A' is uninitialized. Only dereference 'A' in the other case. if (!WaMArch.empty()) - Diag << "march=" << WaMArch; + Diag << "-march=" << WaMArch; else - Diag << A->getOption().getName() << A->getValue(); + Diag << A->getSpelling() << A->getValue(); } if (Args.getLastArg(options::OPT_mgeneral_regs_only)) { @@ -330,7 +330,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, continue; } D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Scope; + << A->getSpelling() << Scope; break; } } diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index 5b3f7c1..67dec7c 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -122,7 +122,7 @@ static void checkARMArchName(const Driver &D, const Arg *A, const ArgList &Args, (Split.second.size() && !DecodeARMFeatures(D, Split.second, CPUName, ArchKind, Features, ArgFPUID))) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getSpelling() << A->getValue(); } // Check -mcpu=. Needs ArchName to handle -mcpu=generic. @@ -139,7 +139,7 @@ static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args, (Split.second.size() && !DecodeARMFeatures(D, Split.second, CPU, ArchKind, Features, ArgFPUID))) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getSpelling() << A->getValue(); } bool arm::useAAPCSForMachO(const llvm::Triple &T) { @@ -879,7 +879,7 @@ fp16_fml_fallthrough: continue; } D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Scope; + << A->getSpelling() << Scope; break; } } diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp b/clang/lib/Driver/ToolChains/Arch/Mips.cpp index c374d74..088eecf 100644 --- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp +++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp @@ -306,7 +306,7 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, } } else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } if (Arg *A = Args.getLastArg(options::OPT_mabs_EQ)) { @@ -327,7 +327,7 @@ void mips::getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, } } else { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } } diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp index 081e8ff..90a2c3a 100644 --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -73,7 +73,7 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple, CPU = llvm::sys::getHostCPUName(); if (!getRISCFeaturesFromMcpu(Triple, CPU, Features)) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << CPU; + << A->getSpelling() << CPU; } // Handle features corresponding to "-ffixed-X" options diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index d847db7..3c8adf3 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -255,7 +255,7 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, Features.push_back("+harden-sls-ijmp"); } else if (Scope != "none") { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Scope; + << A->getSpelling() << Scope; } } } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4e404c5..8edef65 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -958,7 +958,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, CmdArgs.push_back("-fprofile-update=atomic"); else if (Val != "single") D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } else if (SanArgs.needsTsanRt()) { CmdArgs.push_back("-fprofile-update=atomic"); } @@ -1141,7 +1141,7 @@ static void RenderDebugInfoCompressionArgs(const ArgList &Args, } } else { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } } @@ -1673,7 +1673,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, Scope = A->getValue(); if (Scope != "none" && Scope != "non-leaf" && Scope != "all") D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Scope; + << A->getSpelling() << Scope; Key = "a_key"; IndirectBranches = false; } else { @@ -1681,7 +1681,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, llvm::ARM::ParsedBranchProtection PBP; if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg)) D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << DiagMsg; + << A->getSpelling() << DiagMsg; if (!isAArch64 && PBP.Key == "b_key") D.Diag(diag::warn_unsupported_branch_protection) << "b-key" << A->getAsString(Args); @@ -1902,7 +1902,7 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, } else if (!Val.equals("scalable")) // Handle the unsupported values passed to msve-vector-bits. D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } AddAAPCSVolatileBitfieldArgs(Args, CmdArgs); @@ -2059,7 +2059,7 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-mips-compact-branches=" + Val)); } else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } else D.Diag(diag::warn_target_unsupported_compact_branches) << CPUName; } @@ -2294,7 +2294,7 @@ void Clang::AddX86TargetArgs(const ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-inline-asm=" + Value)); } else { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } else if (D.IsCLMode()) { CmdArgs.push_back("-mllvm"); @@ -2377,7 +2377,7 @@ void Clang::AddLanaiTargetArgs(const ArgList &Args, if (Mregparm != 4) { getToolChain().getDriver().Diag( diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } } @@ -2558,7 +2558,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, ImplicitIt = A->getValue(); if (!CheckARMImplicitITArg(ImplicitIt)) D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << ImplicitIt; + << A->getSpelling() << ImplicitIt; continue; default: break; @@ -2721,7 +2721,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C, D.PrintVersion(C, llvm::outs()); } else { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } } @@ -2855,7 +2855,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, TrappingMath = true; } else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; break; } } @@ -2942,7 +2942,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, LastSeenFfpContractOption = Val; } else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; break; } @@ -2970,7 +2970,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, TrappingMath = TrappingMathPresent = true; } else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; break; } @@ -2982,7 +2982,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, FPEvalMethod = Val; else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; break; } @@ -3436,7 +3436,7 @@ static void RenderTrivialAutoVarInitOptions(const Driver &D, TrivialAutoVarInit = Val; else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; break; } } @@ -4094,7 +4094,7 @@ DwarfFissionKind tools::getDebugFissionKind(const Driver &D, return DwarfFissionKind::Single; D.Diag(diag::err_drv_unsupported_option_argument) - << Arg->getOption().getName() << Arg->getValue(); + << Arg->getSpelling() << Arg->getValue(); return DwarfFissionKind::None; } @@ -7879,7 +7879,7 @@ void ClangAs::AddX86TargetArgs(const ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-x86-asm-syntax=" + Value)); } else { getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } } diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 6c397c6..30fca3a 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -296,7 +296,7 @@ void tools::addLinkerCompressDebugSectionsOption( CmdArgs.push_back(Args.MakeArgString("--compress-debug-sections=" + V)); else TC.getDriver().Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << V; + << A->getSpelling() << V; } } diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 43f6a82..c901623 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -104,7 +104,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args, // Clang's "fast-honor-pragmas" option is not supported because it is // non-standard D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } for (const Arg *A : Args) { diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index a33e684..8236451 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -729,7 +729,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, Args.MakeArgString("--compress-debug-sections=" + Twine(Value))); } else { D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Value; + << A->getSpelling() << Value; } } } diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index 93b987c..703a470 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -40,7 +40,7 @@ static void handleHVXWarnings(const Driver &D, const ArgList &Args) { StringRef Val = A->getValue(); if (!Val.equals_insensitive("64b") && !Val.equals_insensitive("128b")) D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; + << A->getSpelling() << Val; } } diff --git a/clang/lib/Driver/ToolChains/MSP430.cpp b/clang/lib/Driver/ToolChains/MSP430.cpp index bc78985..4edc1d2 100644 --- a/clang/lib/Driver/ToolChains/MSP430.cpp +++ b/clang/lib/Driver/ToolChains/MSP430.cpp @@ -101,7 +101,7 @@ void msp430::getMSP430TargetFeatures(const Driver &D, const ArgList &Args, Features.push_back("+hwmultf5"); } else { D.Diag(clang::diag::err_drv_unsupported_option_argument) - << HWMultArg->getOption().getName() << HWMult; + << HWMultArg->getSpelling() << HWMult; } } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index b004c6c..088e83b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1711,7 +1711,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, StringRef Value = A->getValue(); if (Value != "simple" && Value != "mangled") Diags.Report(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(); + << A->getSpelling() << A->getValue(); Opts.setDebugSimpleTemplateNames( StringRef(A->getValue()) == "simple" ? codegenoptions::DebugTemplateNamesKind::Simple diff --git a/clang/test/Driver/mingw-cfguard.c b/clang/test/Driver/mingw-cfguard.c index d929704..f69b9c0 100644 --- a/clang/test/Driver/mingw-cfguard.c +++ b/clang/test/Driver/mingw-cfguard.c @@ -25,4 +25,4 @@ // GUARD_NOCHECKS-NOT: "--no-guard-cf" // RUN: %clang --target=x86_64-w64-windows-gnu -### %s -mguard=xxx 2>&1 | FileCheck -check-prefix=GUARD_UNKNOWN %s -// GUARD_UNKNOWN: error: unsupported argument 'xxx' to option '--mguard=' +// GUARD_UNKNOWN: error: unsupported argument 'xxx' to option '-mguard=' diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index f218014..043c352 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -688,7 +688,7 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc, fpContractMode = LangOptions::FPM_Fast; else { diags.Report(clang::diag::err_drv_unsupported_option_argument) - << a->getOption().getName() << val; + << a->getSpelling() << val; return false; }