This is an archive of the discontinued LLVM Phabricator instance.

[AsmPrinter] Reject ptrtoint to larger size in lowerConstant()
ClosedPublic

Authored by nikic on Jul 22 2022, 8:03 AM.

Details

Summary

When using a ptrtoint to a size larger than the pointer width in a global initializer, we currently create a ptr & low_bit_mask style MCExpr, which will later result in a relocation error during object file emission.

This patch rejects the constant expression already during lowerConstant(), which results in a much clearer error message that references the constant expression at fault.

This fixes https://github.com/llvm/llvm-project/issues/56400, for certain definitions of "fix".

Diff Detail

Event Timeline

nikic created this revision.Jul 22 2022, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 8:03 AM
nikic requested review of this revision.Jul 22 2022, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2022, 8:03 AM
MaskRay accepted this revision.Jul 22 2022, 4:59 PM

Looks great!

llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
1

Add a file-level comment that this is intentionally unsupported.

Otherwise from not --crash it is usually unclear whether it is a limitation or intentional.

This revision is now accepted and ready to land.Jul 22 2022, 4:59 PM
This revision was landed with ongoing or failed builds.Jul 25 2022, 1:18 AM
This revision was automatically updated to reflect the committed changes.