Author: Fangrui Song Date: 2022-05-27T22:28:39-07:00 New Revision: 3b4500014a481f0de300f42e1e59a8137d136ed1
URL: https://github.com/llvm/llvm-project/commit/3b4500014a481f0de300f42e1e59a8137d136ed1 DIFF: https://github.com/llvm/llvm-project/commit/3b4500014a481f0de300f42e1e59a8137d136ed1.diff LOG: [Driver] Replace err_invalid_branch_protection with err_drv_unsupported_option_argument The convention is to use err_drv_unsupported_option_argument instead of adding a new diagnostic for every option. Added: Modified: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/aarch64-security-options.c clang/test/Driver/arm-security-options.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index ef08198273a16..9f4864a33a33b 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -424,8 +424,6 @@ def warn_ignoring_verify_debuginfo_preserve_export : Warning< "ignoring -fverify-debuginfo-preserve-export=%0 because " "-fverify-debuginfo-preserve wasn't enabled">, InGroup<UnusedCommandLineArgument>; -def err_invalid_branch_protection: Error < - "invalid branch protection option '%0' in '%1'">; def warn_unsupported_branch_protection: Warning < "invalid branch protection option '%0' in '%1'">, InGroup<BranchProtection>; def err_sls_hardening_arm_not_supported : Error< diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 367001ddd2d39..936682e49299e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1693,18 +1693,17 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, if (A->getOption().matches(options::OPT_msign_return_address_EQ)) { Scope = A->getValue(); - if (!Scope.equals("none") && !Scope.equals("non-leaf") && - !Scope.equals("all")) - D.Diag(diag::err_invalid_branch_protection) - << Scope << A->getAsString(Args); + if (Scope != "none" && Scope != "non-leaf" && Scope != "all") + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Scope; Key = "a_key"; IndirectBranches = false; } else { StringRef DiagMsg; llvm::ARM::ParsedBranchProtection PBP; if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg)) - D.Diag(diag::err_invalid_branch_protection) - << DiagMsg << A->getAsString(Args); + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << DiagMsg; if (!isAArch64 && PBP.Key == "b_key") D.Diag(diag::warn_unsupported_branch_protection) << "b-key" << A->getAsString(Args); diff --git a/clang/test/Driver/aarch64-security-options.c b/clang/test/Driver/aarch64-security-options.c index b4bb57e71aa79..2044dbd732ed9 100644 --- a/clang/test/Driver/aarch64-security-options.c +++ b/clang/test/Driver/aarch64-security-options.c @@ -44,11 +44,11 @@ // CONFLICT: "-msign-return-address=none" -// BAD-RA-PROTECTION: invalid branch protection option 'foo' in '-msign-return-address={{.*}}' -// BAD-BP-PROTECTION: invalid branch protection option 'bar' in '-mbranch-protection={{.*}}' +// BAD-RA-PROTECTION: unsupported argument 'foo' to option '-msign-return-address=' +// BAD-BP-PROTECTION: unsupported argument 'bar' to option '-mbranch-protection=' -// BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}' -// BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}' +// BAD-B-KEY-COMBINATION: unsupported argument 'b-key' to option '-mbranch-protection=' +// BAD-LEAF-COMBINATION: unsupported argument 'leaf' to option '-mbranch-protection=' // Check that the linker driver doesn't warn about -mbranch-protection=standard // as an unused option. diff --git a/clang/test/Driver/arm-security-options.c b/clang/test/Driver/arm-security-options.c index fc1b5da78d2cf..b181f19370715 100644 --- a/clang/test/Driver/arm-security-options.c +++ b/clang/test/Driver/arm-security-options.c @@ -85,9 +85,9 @@ // BTE-OFF-NOT: "-mbranch-target-enforce" // BTE-ON: "-mbranch-target-enforce" -// BAD-BP-PROTECTION: invalid branch protection option 'bar' in '-mbranch-protection={{.*}}' +// BAD-BP-PROTECTION: unsupported argument 'bar' to option '-mbranch-protection=' -// BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}' -// BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}' +// BAD-B-KEY-COMBINATION: unsupported argument 'b-key' to option '-mbranch-protection=' +// BAD-LEAF-COMBINATION: unsupported argument 'leaf' to option '-mbranch-protection=' // INCOMPATIBLE-ARCH: '-mbranch-protection=' option is incompatible with the '{{.*}}' architecture _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits