[clang] 6ff6191 - [Driver] Reject -fptrauth-intrinsics on non-AArch64 targets
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 00:04:24 PDT 2024
Author: Fangrui Song
Date: 2024-03-26T00:04:19-07:00
New Revision: 6ff61914a1ef2c05702ba73cf31ffdeed59c1740
URL: https://github.com/llvm/llvm-project/commit/6ff61914a1ef2c05702ba73cf31ffdeed59c1740
DIFF: https://github.com/llvm/llvm-project/commit/6ff61914a1ef2c05702ba73cf31ffdeed59c1740.diff
LOG: [Driver] Reject -fptrauth-intrinsics on non-AArch64 targets
And add a driver test missing from the original patch #65996.
Added:
clang/test/Driver/aarch64-ptrauth.c
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index b0d90c776b58a9..29066ea14280c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4105,12 +4105,8 @@ defm strict_return : BoolFOption<"strict-return",
" of a non-void function as unreachable">,
PosFlag<SetTrue>>;
-let Group = f_Group in {
- let Visibility = [ClangOption,CC1Option] in {
- def fptrauth_intrinsics : Flag<["-"], "fptrauth-intrinsics">,
- HelpText<"Enable pointer authentication intrinsics">;
- }
- def fno_ptrauth_intrinsics : Flag<["-"], "fno-ptrauth-intrinsics">;
+let Flags = [TargetSpecific] in {
+defm ptrauth_intrinsics : OptInCC1FFlag<"ptrauth-intrinsics", "Enable pointer authentication intrinsics">;
}
def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 86a287db72a4eb..3bcacff7724c7d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1776,6 +1776,9 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
}
AddUnalignedAccessWarning(CmdArgs);
+
+ Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_intrinsics,
+ options::OPT_fno_ptrauth_intrinsics);
}
void Clang::AddLoongArchTargetArgs(const ArgList &Args,
@@ -7258,10 +7261,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// -fno-common is the default, set -fcommon only when that flag is set.
Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
- if (Args.hasFlag(options::OPT_fptrauth_intrinsics,
- options::OPT_fno_ptrauth_intrinsics, false))
- CmdArgs.push_back("-fptrauth-intrinsics");
-
// -fsigned-bitfields is default, and clang doesn't yet support
// -funsigned-bitfields.
if (!Args.hasFlag(options::OPT_fsigned_bitfields,
diff --git a/clang/test/Driver/aarch64-ptrauth.c b/clang/test/Driver/aarch64-ptrauth.c
new file mode 100644
index 00000000000000..1a69b2c6edfb17
--- /dev/null
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -0,0 +1,5 @@
+// RUN: %clang -### -c --target=aarch64 -fno-ptrauth-intrinsics -fptrauth-intrinsics %s 2>&1 | FileCheck %s --check-prefix=INTRIN
+// INTRIN: "-cc1"{{.*}} "-fptrauth-intrinsics"
+
+// RUN: not %clang -### -c --target=x86_64 -fptrauth-intrinsics %s 2>&1 | FileCheck %s --check-prefix=ERR
+// ERR: error: unsupported option '-fptrauth-intrinsics' for target '{{.*}}'
More information about the cfe-commits
mailing list