This is an archive of the discontinued LLVM Phabricator instance.

[LangRef] Document integer hexadecimal constants
ClosedPublic

Authored by luke on Aug 18 2023, 8:41 AM.

Details

Summary

It's possible to write an integer constant in hexadecimal, but you need to
prefix it with u or s. I couldn't find this mentioned anywhere in the LangRef,
so this adds a small note about it.

Diff Detail

Event Timeline

luke created this revision.Aug 18 2023, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 8:41 AM
luke requested review of this revision.Aug 18 2023, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 8:41 AM
arsenm requested changes to this revision.Aug 18 2023, 8:47 AM

Thanks, I’ve known this existed but couldn’t ever remember the syntax. Can you add some more examples?

This revision now requires changes to proceed.Aug 18 2023, 8:47 AM
luke updated this revision to Diff 551558.Aug 18 2023, 9:54 AM

Add some more examples

luke added a comment.Aug 18 2023, 9:54 AM

Thanks, I’ve known this existed but couldn’t ever remember the syntax. Can you add some more examples?

After playing about a bit, I'm actually a bit surprised by how signed hex constants behave. They're sign extended from the number of active bits, so it's not actually possible to represent a positive signed constant. I've traced it back to this commit from 2007: https://github.com/llvm/llvm-project/commit/7957de7949d7f45d0adc81dde38ae0468f1cd09d

I've documented it anyway.

arsenm accepted this revision.Aug 18 2023, 10:02 AM
This revision is now accepted and ready to land.Aug 18 2023, 10:02 AM
This revision was landed with ongoing or failed builds.Aug 18 2023, 10:05 AM
This revision was automatically updated to reflect the committed changes.