This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Limit FunctionTypeExtraBitfields::NumExceptionType to 16 bits.
ClosedPublic

Authored by sdesmalen on Jun 5 2023, 3:21 AM.

Details

Summary

In https://reviews.llvm.org/D127762#4102578 @erichkeane suggested to
limit size of this field to 16bits, such that the field that encodes the
SME attributes for a function fall within the alignment of the struct for
32bit platforms.

Standard implimits defines the minimum handlers per try block to 256,
which suggests that 16bits should be more than sufficient for most
programs. Erich also pointed out that exception specs are being
deprecated and are rarely used, so hopefully this change is safe to make.

Diff Detail

Event Timeline

sdesmalen created this revision.Jun 5 2023, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 3:21 AM
sdesmalen requested review of this revision.Jun 5 2023, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 3:21 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane accepted this revision.Jun 5 2023, 6:14 AM
This revision is now accepted and ready to land.Jun 5 2023, 6:14 AM
tbaeder added a subscriber: tbaeder.Jun 5 2023, 6:20 AM
tbaeder added inline comments.
clang/include/clang/AST/Type.h
3956

Isn't using a uint16_t preferred over a bitfield?

erichkeane added inline comments.Jun 5 2023, 6:22 AM
clang/include/clang/AST/Type.h
3956

Ah, thats a great point, yes, I think that is probably better here! I like the assert on setting it (particularly because we're shrinking it!), but that idea makes this patch much smaller.

sdesmalen added inline comments.Jun 5 2023, 7:01 AM
clang/include/clang/AST/Type.h
3956

The reason for making this a bitfield rather than uint16_t is because D127762 extends the struct with another (bit)field:

/// Any AArch64 SME ACLE type attributes that need to be propagated
/// on declarations and function pointers.
unsigned AArch64SMEAttributes : 6;

I thought having this all be bitfields made more sense, but I'm happy to change it to a uint16_t if that is preferred.

that idea makes this patch much smaller

I suspect that the assert is still required to ensure that the value stored fits the value? Using uint16_t doesn't change that, or did I miss something? :)

erichkeane added inline comments.Jun 5 2023, 7:05 AM
clang/include/clang/AST/Type.h
3956

We don't need them all to be bitfields, they'll take up the same amount of space with out it, and save us a bit of oddity.

I like the assert still as well, but since this size is set in 1 place, an assert there would be fine as well.

sdesmalen updated this revision to Diff 528431.Jun 5 2023, 7:19 AM

Use uint16_t instead of unsigned bitfield.
Also removed accessor methods in favour of assert at point of writing NumExceptionType.

clang/include/clang/AST/Type.h
3956

Okay that makes sense, thanks.

erichkeane requested changes to this revision.Jun 5 2023, 7:21 AM
erichkeane added inline comments.
clang/lib/AST/Type.cpp
3374–3377

So this isn't a place where we're allowed to use auto. We can only use it if the type is listed on the RHS (like in the case of casts/etc).

This revision now requires changes to proceed.Jun 5 2023, 7:21 AM
sdesmalen updated this revision to Diff 528433.Jun 5 2023, 7:24 AM

Use size_t instead of auto.

clang/lib/AST/Type.cpp
3374–3377

You're absolutely right, sorry about that!

erichkeane accepted this revision.Jun 5 2023, 7:25 AM
This revision is now accepted and ready to land.Jun 5 2023, 7:25 AM