[cfe-commits] [PATCH] Fixing bug for function calls w/ diff addr spaces

Eli Friedman eli.friedman at gmail.com
Thu Jun 21 17:35:17 PDT 2012


On Thu, Jun 21, 2012 at 4:57 PM, Tanya Lattner <lattner at apple.com> wrote:
>
> On Jun 15, 2012, at 3:31 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>
>> On Thu, Jun 14, 2012 at 3:43 PM, Tanya Lattner <lattner at apple.com> wrote:
>>>
>>> The attached patch fixes a crash in CodeGen when a struct is passed indirectly by value to another function by converting the address space. I've included a test case.
>>>
>>> Please review.
>>
>> Here's a testcase which actually fails unpatched on x86-64:
>>
>> // RUN: %clang_cc1 %s -ffake-address-space-map -emit-llvm -o %t
>> typedef struct {
>>  long long s;
>>  float loc[8];
>> } AStruct;
>> void foo(AStruct s);
>> kernel void StructTest(__global AStruct *s_in )
>> {
>>  foo(s_in[0]);
>> }
>>
>> IIRC, we can't just blindly bitcast: address space 0 isn't compatible
>> with every other address space on every platform.
>
> Yes, you are right. I believe that this should throw an error at the bare minimum here right? Should this be caught in Sema somewhere instead?

The given testcase is semantically sound: the __global qualifier
disappears once we perform an lvalue-to-rvalue conversion.  It's just
that byval in LLVM IR has slightly strange semantics, which means we
have to introduce an extra copy into the IR.

-Eli




More information about the cfe-commits mailing list