This is an archive of the discontinued LLVM Phabricator instance.

Tame a few enum size tests when using -fshort-enums on ARM.
ClosedPublic

Authored by jroelofs on Aug 12 2014, 9:54 AM.

Details

Diff Detail

Event Timeline

jroelofs updated this revision to Diff 12402.Aug 12 2014, 9:54 AM
jroelofs retitled this revision from to Tame a few enum size tests when using -fshort-enums on ARM..
jroelofs updated this object.
jroelofs edited the test plan for this revision. (Show Details)
jroelofs added a reviewer: mclow.lists.
jroelofs added a subscriber: Unknown Object (MLST).

Not really a review, as I don't know how these tests are supposed to work, but one comment that you may well know and have made an active decision on already (but just in case not)...

libcxx/test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp
55

I think the preprocessor rules mean that __ARM_SIZEOF_MINIMAL_ENUM gets the notional value 0 if it's not defined, so you can probably skip the first condition if you want.

EricWF added a subscriber: EricWF.Aug 14 2014, 6:35 PM

The patch you have now looks good but I think a more universal solution might be better since these tests will fail whenever -f-short-enums is used. Something like:

test_make_signed<const Enum, std::conditional<sizeof(Enum) == sizeof(int), const int, const signed char>::type>()

Out of curiosity how are you getting the -fshort-enums flag into lit to test?

The patch you have now looks good but I think a more universal solution might be better since these tests will fail whenever -f-short-enums is used. Something like:

I'm not sure I understand... This works on ARM for both -fshort-enums and -fno-short-enums.

test_make_signed<const Enum, std::conditional<sizeof(Enum) == sizeof(int), const int, const signed char>::type>()

That seems better on the surface, but assumes that short enums are char sized, which might not be the case on all platforms. I think that the version that checks __ARM_SIZEOF_MINIMAL_ENUM does a better job of calling out the fact that it's a weird case.

Out of curiosity how are you getting the -fshort-enums flag into lit to test?

I need ABI compatibility with a bare-metal GCC toolchain and that toolchain defaults bare-metal AAPCS targets to -fshort-enums, so my driver sets it.

EricWF edited edge metadata.Aug 15 2014, 11:25 AM

I'm not sure I understand... This works on ARM for both -fshort-enums and -fno-short-enums.

Sorry, I meant the original test fails whenever -fshort-enums is used. Not just on ARM. Your patch is definitely a lot better at calling out the weird behavior. Optimally I would like to make the workaround less ARM specific, like how wchar_t is handled.

I'm not convinced that we are going to run into cases where sizeof(Enum) is not the same as sizeof(int) or sizeof(char).
I apologize. I'm not trying to be difficult. My main concern is introducing a workaround that only a very small set of users can test and reason about. If '-fshort-enums' is causing this failure then I want to work around the switch and not how an architecture handles the switch.

Ah, ok. Now we're on the same page. I've changed my mind, I don't see a better platform agnostic way of looking for short enums than your suggestion... so I think that's the best option.

I'll make the change, and commit.

jroelofs accepted this revision.Aug 15 2014, 2:44 PM
jroelofs added a reviewer: jroelofs.

r215769

This revision is now accepted and ready to land.Aug 15 2014, 2:44 PM
jroelofs closed this revision.Aug 15 2014, 2:44 PM