This is an archive of the discontinued LLVM Phabricator instance.

Fix UB in DwarfExpression::emitLegacyZExt()
ClosedPublic

Authored by aprantl on Jan 25 2022, 1:28 PM.

Details

Summary

A shift-left > 63 triggers a UBSAN failure. This patch kicks the can down the road (to the consumer) by emitting a more compact representation of the shift computation in DWARF expressions.

Diff Detail

Event Timeline

aprantl created this revision.Jan 25 2022, 1:28 PM
aprantl requested review of this revision.Jan 25 2022, 1:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 1:28 PM
aprantl updated this revision to Diff 403022.Jan 25 2022, 1:35 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jan 25 2022, 1:53 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.

Apologies, I accidentally pushed this commit instead of a different one. Reverted in 3efa016d4c1a, this one still needs to be reviewed!

Looks like https://reviews.llvm.org/D117965 caused that. Sorry for the noise.

JDevlieghere added inline comments.Jan 25 2022, 4:20 PM
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
688

I had some trouble figuring out what the 1+1+1+1+1 was supposed to represent. In case anyone is wondering it's 1 byte per DWARF opcode and 1 byte for the small ULEB128 in the alternative encoding below. Maybe we should make that more clear in the comment or used a named temporary/

Also, should we use (FromBits+6)/7 to ensure we always round up?

aprantl updated this revision to Diff 403079.Jan 25 2022, 4:40 PM

Address review feedback!

aprantl updated this revision to Diff 403085.Jan 25 2022, 5:09 PM

Patch test.

JDevlieghere reopened this revision.Jan 25 2022, 5:16 PM
JDevlieghere accepted this revision.

Thanks Adrian. LGTM

This revision is now accepted and ready to land.Jan 25 2022, 5:16 PM
This revision was landed with ongoing or failed builds.Jan 26 2022, 10:57 AM
This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.Jan 26 2022, 12:18 PM

Hi Adrian, the test you updated in your commit is failing on the PS4 linux bot, can you take a look?

https://lab.llvm.org/buildbot/#/builders/139/builds/16906

xbolva00 added inline comments.
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
688

Agree with you. This should be reworked /commented more.