Skip to content

Commit 3c1af4c

Browse files
committed
Check the original LangOptions instead of CodeGenOptions
1 parent f69ae09 commit 3c1af4c

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,31 +202,25 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
202202
}
203203

204204
void AArch64TargetInfo::validatePAuthOptions(
205-
DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts) const {
206-
auto NeedsHWSupport = [](const PointerAuthSchema &Schema) {
207-
switch (Schema.getKind()) {
208-
case PointerAuthSchema::Kind::None:
209-
case PointerAuthSchema::Kind::Soft:
210-
return false;
211-
case PointerAuthSchema::Kind::ARM8_3:
212-
return true;
213-
}
214-
llvm_unreachable("Unexpected authentication kind");
215-
};
205+
DiagnosticsEngine &Diags, const LangOptions &Opts) const {
206+
if (Opts.SoftPointerAuth)
207+
return;
216208

217209
bool NeedsFeatPAuth = false;
218-
NeedsFeatPAuth |= CGOpts.PointerAuth.ReturnAddresses;
219-
for (auto Schema : CGOpts.PointerAuth.getAllUsedSchemas())
220-
NeedsFeatPAuth |= NeedsHWSupport(Schema);
210+
// FIXME: Some ptrauth_* intrinsics can be implemented without FEAT_PAuth.
211+
// At now, checking conservatively.
212+
NeedsFeatPAuth |= Opts.PointerAuthIntrinsics;
213+
NeedsFeatPAuth |= Opts.PointerAuthCalls;
214+
NeedsFeatPAuth |= Opts.PointerAuthReturns;
215+
NeedsFeatPAuth |= Opts.getPointerAuthObjcIsaAuthentication() != PointerAuthenticationMode::None;
221216

222217
if (NeedsFeatPAuth && !HasPAuth)
223218
Diags.Report(diag::err_pauth_cpu_feature_missing);
224219
}
225220

226-
void AArch64TargetInfo::adjustTargetOptions(DiagnosticsEngine &Diags,
227-
const CodeGenOptions &CGOpts,
228-
TargetOptions &TargetOpts) const {
229-
validatePAuthOptions(Diags, CGOpts);
221+
void AArch64TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
222+
TargetInfo::adjust(Diags, Opts);
223+
validatePAuthOptions(Diags, Opts);
230224
}
231225

232226
StringRef AArch64TargetInfo::getABI() const { return ABI; }

clang/lib/Basic/Targets/AArch64.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
9292
AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
9393

9494
void validatePAuthOptions(DiagnosticsEngine &Diags,
95-
const CodeGenOptions &CGOpts) const;
96-
void adjustTargetOptions(DiagnosticsEngine &Diags,
97-
const CodeGenOptions &CGOpts,
98-
TargetOptions &TargetOpts) const override;
95+
const LangOptions &Opts) const;
96+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9997

10098
StringRef getABI() const override;
10199
bool setABI(const std::string &Name) override;

clang/test/CodeGen/ptrauth-cpu-feature.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
// Test that features requiring FEAT_PAuth fail early:
1+
// REQUIRES: aarch64-registered-target
2+
3+
// Test that features requiring FEAT_PAuth fail early if the requirement is not met:
4+
//
25
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=FAIL
36
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-calls 2>&1 | FileCheck %s --check-prefix=FAIL
47
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-returns 2>&1 | FileCheck %s --check-prefix=FAIL
58
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-objc-isa 2>&1 | FileCheck %s --check-prefix=FAIL
69
//
7-
// Note: at the time of writing, the following options are gated on -fptrauth-calls:
8-
// -fptrauth-init-fini
9-
// -fptrauth-function-pointer-type-discrimination
10-
// -fptrauth-vtable-pointer-address-discrimination
11-
// -fptrauth-vtable-pointer-type-discrimination
12-
// -fptrauth-block-descriptor-pointers
10+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=apple-a12 -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
11+
12+
// Test that the following options are still gated on -fptrauth-calls.
13+
// If they are not, in assertion builds they would fail at asm printing time:
14+
//
15+
// RUN: %clang -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-init-fini
16+
// RUN: %clang -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-function-pointer-type-discrimination
17+
// RUN: %clang -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-address-discrimination
18+
// RUN: %clang -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-type-discrimination
19+
// RUN: %clang -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-block-descriptor-pointers
1320

1421
// Test that v8.2-compatible code is generated, if possible:
22+
//
23+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -msign-return-address=all 2>&1 | FileCheck %s --check-prefix=COMPAT
1524
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pac-ret 2>&1 | FileCheck %s --check-prefix=COMPAT
1625

17-
// Several targets imply +pauth:
18-
// RUN: %clang %s -S -o - -target arm64e-apple-ios 2>&1 | FileCheck %s --check-prefix=PAUTH
26+
// arm64e has ptrauth enabled and assumes modern enough CPU by default:
27+
//
28+
// RUN: %clang %s -S -o - -target arm64e-apple-ios 2>&1 | FileCheck %s --check-prefix=PAUTH
29+
// RUN: not %clang %s -S -o - -target arm64e-apple-ios -mcpu=cortex-a72 2>&1 | FileCheck %s --check-prefix=FAIL
1930

2031
void ext(void);
2132

@@ -24,7 +35,10 @@ int f(void) {
2435
return 0;
2536
}
2637

27-
// FAIL: error: A feature is requested that needs CPU with Pointer Authentication support
38+
// FIXME At now, the error message is printed twice.
39+
// Ideally, this should be fixed, but it seems rather harmless.
40+
//
41+
// FAIL-2: error: A feature is requested that needs CPU with Pointer Authentication support
2842

2943
// COMPAT: f:
3044
// COMPAT: hint #25

0 commit comments

Comments
 (0)