Crash on conditional operation with address_space pointer

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.

- Leo

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.

Does this mean the check during the BitCast codegen shouldn't be there
in the first place?

Does this mean the check during the BitCast codegen shouldn't be there
in the first place?

We should not be generating code for this program, correct.

John.

Oh. Should an error be printed here instead, or it's fine to let it
crash I suppose since the code shouldn't be generate in the first
place?

It seems that at least 3 tests expect this conditional operator to
print a "pointer type mismatch" warning.

Oh. Should an error be printed here instead, or it's fine to let it
crash I suppose since the code shouldn't be generate in the first
place?

It seems that at least 3 tests expect this conditional operator to
print a "pointer type mismatch" warning.

The compiler should definitely never crash. That sounds like the right diagnostic
we should be emitting, except I don't think it can be just a warning for an
address-space mismatch.

John.

Oh I see. I misinterpreted a few things. I'll change the patch to
print something from err_typecheck_incompatible_address_space instead
in addition to raising the warning.

Oh I see. I misinterpreted a few things. I'll change the patch to
print something from err_typecheck_incompatible_address_space instead
in addition to raising the warning.

Great, please CC me on the review when you put it up.

John.

Added you to https://reviews.llvm.org/D50278