This is an archive of the discontinued LLVM Phabricator instance.

Implement _ExtInt conversion rules
ClosedPublic

Authored by aaron.ballman on Jul 14 2021, 9:36 AM.

Details

Summary

Clang implemented the _ExtInt datatype as a bit-precise integer type, which was then proposed to WG14. WG14 has accepted the proposal (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2709.pdf), but Clang requires some additional work as a result.

In the original Clang implementation, we elected to disallow implicit conversions involving these types until after WG14 finalized the rules. This patch implements the rules decided by WG14: no integer promotion for bit-precise types, conversions prefer the larger of the two types and in the event of a tie (say _ExtInt(32) and a 32-bit int), the standard type wins.

There are more changes still needed to conform to N2709, but those will be handled in follow-up patches.

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Jul 14 2021, 9:36 AM
aaron.ballman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 9:36 AM
erichkeane added inline comments.Jul 14 2021, 9:40 AM
clang/test/Sema/ext-int.c
7–9

Wouldn't mind some type-checking tests here if possible. Or at least SOMEWHERE to make sure this produces the correct types, something with a static-assert would be great!

aaron.ballman added inline comments.Jul 14 2021, 9:43 AM
clang/test/Sema/ext-int.c
7–9

There's not a super easy way to do is_same in C, but I could add some AST dumping tests that involve __typeof__ if that'd work for you?

erichkeane added inline comments.Jul 14 2021, 9:47 AM
clang/test/Sema/ext-int.c
7–9

yep! That'd be fine.

rsmith added inline comments.Jul 14 2021, 10:30 AM
clang/test/Sema/ext-int.c
7–9

Can you build is_same out of _Generic? Eg, _Static_assert(_Generic(b ? s30 : s31a, EI31: 1, default: 0, "");

aaron.ballman added inline comments.Jul 14 2021, 10:33 AM
clang/test/Sema/ext-int.c
7–9

@rsmith -- great minds think alike, I was just heading down that route. :-)

Added more test coverage in C for conversion type results.

aaron.ballman marked 3 inline comments as done.Jul 14 2021, 10:36 AM

Ping. FWIW, I'm hoping to get these changes into the Clang 13 branch before we split off. I don't think we'll get fully conforming support for the feature in Clang 13 (we need some ABI discussion before I think we'll be ready to rename _ExtInt to _BitInt, but I'd like to get as close to conforming as possible).

This revision is now accepted and ready to land.Jul 19 2021, 12:10 PM
erichkeane accepted this revision.Jul 19 2021, 12:26 PM
aaron.ballman closed this revision.Jul 22 2021, 6:14 AM

Thanks for the reviews; I've committed in 6bb042e70024354acc65457e153b40d50cada4f5.