Skip to content

Commit 74995a6

Browse files
authored
AArch64: Do not use report_fatal_error for pauth reloc errors (#145277)
This handling could be better. The wording doesn't follow the error message guidance, and ideally we would emit with a reference the the global variable (but we are currently missing an existing DiagnosticInfo for a global reference. This case might call for a custom ConstantPointerAuth kind). Additionally this could stop using split-file since each error case no longer aborts the compilation, and thus the different cases can coexist in the same file.
1 parent 36dd61f commit 74995a6

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,15 +2254,19 @@ AArch64AsmPrinter::lowerConstantPtrAuth(const ConstantPtrAuth &CPA) {
22542254
uint64_t KeyID = CPA.getKey()->getZExtValue();
22552255
// We later rely on valid KeyID value in AArch64PACKeyIDToString call from
22562256
// AArch64AuthMCExpr::printImpl, so fail fast.
2257-
if (KeyID > AArch64PACKey::LAST)
2258-
report_fatal_error("AArch64 PAC Key ID '" + Twine(KeyID) +
2259-
"' out of range [0, " +
2260-
Twine((unsigned)AArch64PACKey::LAST) + "]");
2257+
if (KeyID > AArch64PACKey::LAST) {
2258+
CPA.getContext().emitError("AArch64 PAC Key ID '" + Twine(KeyID) +
2259+
"' out of range [0, " +
2260+
Twine((unsigned)AArch64PACKey::LAST) + "]");
2261+
KeyID = 0;
2262+
}
22612263

22622264
uint64_t Disc = CPA.getDiscriminator()->getZExtValue();
2263-
if (!isUInt<16>(Disc))
2264-
report_fatal_error("AArch64 PAC Discriminator '" + Twine(Disc) +
2265-
"' out of range [0, 0xFFFF]");
2265+
if (!isUInt<16>(Disc)) {
2266+
CPA.getContext().emitError("AArch64 PAC Discriminator '" + Twine(Disc) +
2267+
"' out of range [0, 0xFFFF]");
2268+
Disc = 0;
2269+
}
22662270

22672271
// Finally build the complete @AUTH expr.
22682272
return AArch64AuthMCExpr::create(Sym, Disc, AArch64PACKey::ID(KeyID),

llvm/test/CodeGen/AArch64/ptrauth-reloc.ll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,38 +139,39 @@
139139

140140
;--- err-key.ll
141141

142-
; RUN: not --crash llc < err-key.ll -mtriple arm64e-apple-darwin 2>&1 \
142+
; RUN: not llc < err-key.ll -mtriple arm64e-apple-darwin 2>&1 \
143143
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-KEY
144-
; RUN: not --crash llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
144+
; RUN: not llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
145145
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-KEY
146146

147-
; RUN: not --crash llc < err-key.ll -mtriple arm64e-apple-darwin \
147+
; RUN: not llc < err-key.ll -mtriple arm64e-apple-darwin \
148148
; RUN: -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
149149
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-KEY
150-
; RUN: not --crash llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth \
150+
; RUN: not llc < err-key.ll -mtriple aarch64-elf -mattr=+pauth \
151151
; RUN: -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
152152
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-KEY
153153

154-
; CHECK-ERR-KEY: LLVM ERROR: AArch64 PAC Key ID '4' out of range [0, 3]
154+
; CHECK-ERR-KEY: error: AArch64 PAC Key ID '4' out of range [0, 3]
155+
155156

156157
@g = external global i32
157158
@g.ref.4.0 = constant ptr ptrauth (ptr @g, i32 4, i64 0)
158159

159160
;--- err-disc.ll
160161

161-
; RUN: not --crash llc < err-disc.ll -mtriple arm64e-apple-darwin 2>&1 \
162+
; RUN: not llc < err-disc.ll -mtriple arm64e-apple-darwin 2>&1 \
162163
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-DISC
163-
; RUN: not --crash llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
164+
; RUN: not llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth 2>&1 \
164165
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-DISC
165166

166-
; RUN: not --crash llc < err-disc.ll -mtriple arm64e-apple-darwin \
167+
; RUN: not llc < err-disc.ll -mtriple arm64e-apple-darwin \
167168
; RUN: -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
168169
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-DISC
169-
; RUN: not --crash llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth \
170+
; RUN: not llc < err-disc.ll -mtriple aarch64-elf -mattr=+pauth \
170171
; RUN: -global-isel -verify-machineinstrs -global-isel-abort=1 2>&1 \
171172
; RUN: | FileCheck %s --check-prefix=CHECK-ERR-DISC
172173

173-
; CHECK-ERR-DISC: LLVM ERROR: AArch64 PAC Discriminator '65536' out of range [0, 0xFFFF]
174+
; CHECK-ERR-DISC: error: AArch64 PAC Discriminator '65536' out of range [0, 0xFFFF]
174175

175176
@g = external global i32
176177
@g.ref.ia.65536 = constant ptr ptrauth (ptr @g, i32 0, i64 65536)

0 commit comments

Comments
 (0)