Skip to content

Commit 6c11ad8

Browse files
atrosinenkokovdan01
authored andcommitted
Proposed fix for PR113152
1 parent d2c61e0 commit 6c11ad8

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,17 +1406,18 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
14061406
GuardedControlStack = PBP.GuardedControlStack;
14071407
}
14081408

1409-
bool HasPtrauthReturns = llvm::any_of(CmdArgs, [](const char *Arg) {
1410-
return StringRef(Arg) == "-fptrauth-returns";
1411-
});
1409+
Arg *PtrauthReturnsArg = Args.getLastArg(options::OPT_fptrauth_returns,
1410+
options::OPT_fno_ptrauth_returns);
1411+
bool HasPtrauthReturns =
1412+
PtrauthReturnsArg &&
1413+
PtrauthReturnsArg->getOption().matches(options::OPT_fptrauth_returns);
14121414
// GCS is currently untested with ptrauth-returns, but enabling this could be
14131415
// allowed in future after testing with a suitable system.
1414-
if (HasPtrauthReturns &&
1415-
(Scope != "none" || BranchProtectionPAuthLR || GuardedControlStack)) {
1416+
if (Scope != "none" || BranchProtectionPAuthLR || GuardedControlStack) {
14161417
if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
14171418
D.Diag(diag::err_drv_unsupported_opt_for_target)
14181419
<< A->getAsString(Args) << Triple.getTriple();
1419-
else
1420+
else if (HasPtrauthReturns)
14201421
D.Diag(diag::err_drv_incompatible_options)
14211422
<< A->getAsString(Args) << "-fptrauth-returns";
14221423
}

clang/test/Frontend/aarch64-ignore-branch-protection-attribute.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// REQUIRES: aarch64-registered-target
22

3-
// RUN: %clang -target aarch64-linux-pauthtest %s -S -emit-llvm -o - 2>&1 | FileCheck --implicit-check-not=warning: %s
4-
// RUN: %clang -target aarch64 -fptrauth-returns %s -S -emit-llvm -o - 2>&1 | FileCheck --implicit-check-not=warning: %s
3+
// RUN: %clang -target aarch64-linux-pauthtest %s -S -emit-llvm -o - 2>&1 | FileCheck --implicit-check-not=warning: %s
4+
// RUN: not %clang -target aarch64 -fptrauth-returns %s -S -emit-llvm -o - 2>&1 | FileCheck --implicit-check-not=warning: --check-prefix=PTRAUTH-RETURNS %s
5+
6+
// Clang fails early, no LLVM IR output produced.
7+
// PTRAUTH-RETURNS: clang: error: unsupported option '-fptrauth-returns' for target 'aarch64'
8+
// PTRAUTH-RETURNS-NOT: attributes
59

610
/// Unsupported with pauthtest, warning emitted
711
__attribute__((target("branch-protection=pac-ret"))) void f1() {}

0 commit comments

Comments
 (0)