[cfe-dev] Crash on conditional operation with address_space pointer

John McCall via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 3 16:28:48 PDT 2018


> On Aug 3, 2018, at 7:03 PM, Leonard Chan via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> Compiling the following causes clang to crash
> 
> char *cmp(__attribute__((address_space(1))) char *x,
> __attribute__((address_space(2))) char *y) {
>  return x < y ? x : y;
> }
> 
> with the message: "wrong cast for pointers in different address
> spaces(must be an address space cast)!"
> 
> The problem seems to be that BitCast is used when
> AddressSpaceConversion should be used instead when casting the `y` to
> a void *. The error is thrown during code gen where a BitCast expects
> the source and dest address space to be the same.
> 
> I submitted a patch (https://reviews.llvm.org/D50278) for a fix where
> we check for differing address spaces in the operands and perform an
> AddressSpaceConversion cast if anyone wants to review it. It seems
> that AddressSpaceConversions though were only available when using
> OpenCL. I'm not familiar with OpenCL and not sure if this was
> intended, but it fixes the crash while still retaining the warning of
> using mismatched pointers and all the clang tests pass.

If address spaces 1 and 2 don't overlap — and absent target-specific
information, the assumption is that they don't — then neither the comparison
nor the conditional operator here should type-check.

John.


More information about the cfe-dev mailing list