This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix a machine verifier ICE when using __builtin_return_address with return address sign and authentication
Needs ReviewPublic

Authored by chill on Jul 23 2020, 5:10 AM.

Details

Summary

When using PAuth instructions in the NOP-space, the compiler can emit an
AUTIxSP instruction in the function epilogue.

In a certain test case, using __builtin_return_address, the compiler causes
the machine verifier to exit with an error after turning

%0 = COPY LR
x0 = COPY killed %0

into

x0 = COPY killed LR

and the backend later emitting

x0 = COPY killed LR
AUTIASP implicit def LR, implicit LR

This is obviously incorrect since LR is live beyond the COPY instruction.

The issue is that lifetime of the return address is not tracked properly. The
backend relies on the callee-saved registers mechanism to ensure LR is
restored before used for return. For the return instruction that's handled with
a little hack to appease the verifier.

This patch employs the same hack for AUTIxSP, marking the implicit LR
operand as undef.

Diff Detail