This is an archive of the discontinued LLVM Phabricator instance.

[AsmPrinter] Fix Crash when Emitting Global Constant of small bit width when targeting Big Endian arch
ClosedPublic

Authored by HazyFish on Nov 17 2022, 4:18 PM.

Details

Summary

For Big Endian, the function emitGlobalConstantLargeInt tries to right shift Realigned by an amount ExtraBitSize in place. However, if the constant to emit has a bit width less than 64 and the bit width is not a multiple of 8, the shift amount will be greater than the bit width of Realigned, which causes assertion error described in issue issue #59055.

This patch fixes the issue by avoiding right shift when bit width is under 64 to avoid the assertion error.

Diff Detail

Event Timeline

HazyFish created this revision.Nov 17 2022, 4:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 4:18 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
HazyFish requested review of this revision.Nov 17 2022, 4:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 4:18 PM
efriedma added inline comments.Nov 28 2022, 3:28 PM
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3273

Please upload patches with context (use "git diff -U100000", or use Arcanist).

Maybe it's clearer to just write:

if (BitWidth >= 64)
  Realigned.lshrInPlace(ExtraBitsSize);
llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll
7

If you can't make update_llc_test_checks.py generate something appropriate, please write an appropriate CHECK line by hand.

Maybe it makes sense to just add a RUN line to an existing test, instead of adding a separate test file?

HazyFish updated this revision to Diff 485418.Dec 27 2022, 2:04 PM
HazyFish edited the summary of this revision. (Show Details)

Address feedback

HazyFish marked 2 inline comments as done.Dec 27 2022, 2:04 PM
Peter accepted this revision.Mar 13 2023, 7:52 PM
This revision is now accepted and ready to land.Mar 13 2023, 7:52 PM
HazyFish updated this revision to Diff 508877.Mar 27 2023, 8:03 PM

Align with upstream

Peter accepted this revision.Mar 27 2023, 10:53 PM
Peter updated this revision to Diff 509226.Mar 29 2023, 12:08 AM

arc land

This revision was landed with ongoing or failed builds.Mar 29 2023, 12:09 AM
This revision was automatically updated to reflect the committed changes.