This is an archive of the discontinued LLVM Phabricator instance.

[SemaCXX] Fix handling of C-style casts from void pointers to pointers in different address space.
Needs ReviewPublic

Authored by mjacob on Dec 2 2015, 4:29 PM.

Details

Summary

When for example handling C-style casts from void * to `int
attribute((address_space(1))) *` in C++ code, Sema previously set the cast
kind to CK_BitCast incorrectly, which caused an assert to fail in CodeGen. This
patch changes Sema to set the cast kind to CK_AddressSpaceConversion if source
and destination point to different address spaces.

Diff Detail

Event Timeline

mjacob updated this revision to Diff 41692.Dec 2 2015, 4:29 PM
mjacob retitled this revision from to [SemaCXX] Fix handling of C-style casts from void pointers to pointers in different address space..
mjacob updated this object.
mjacob added a subscriber: cfe-commits.
rsmith added inline comments.Dec 2 2015, 5:31 PM
lib/Sema/SemaCast.cpp
1081–1083

I would expect to get both a CK_BitCast *and* a CK_AddressSpaceCast created for this case. Note that by not returning CK_BitCast, you lose the checkCastAlign call in the caller.

Instead, can you push this check down into wherever we're building the conversion, so that if we try to create a CK_BitCast that crosses address spaces, we additionally create a CK_AddressSpaceCast?

mjacob added inline comments.Dec 2 2015, 5:51 PM
lib/Sema/SemaCast.cpp
1081–1083

I'm not sure what you mean by "additionally create a CK_AddressSpaceCast". Please clarify.

Would it also be possible to extend all places which call checkCastAlign() to also call it for CK_AddressSpaceCast?