Page MenuHomePhabricator

[PR40778] Generate address space conversion when binding reference to a temporary value in different address space
ClosedPublic

Authored by Anastasia on Feb 25 2019, 9:37 AM.

Diff Detail

Repository
rC Clang

Event Timeline

Anastasia created this revision.Feb 25 2019, 9:37 AM
Anastasia marked an inline comment as done.Feb 25 2019, 9:48 AM
Anastasia added inline comments.
lib/CodeGen/CGCall.cpp
4067 ↗(On Diff #188206)

We have started using performAddrSpaceCast for those but, however, I was very confused about how to get address space of the Clang types correctly here.

I was using this function in a couple of places before but I must admit I am still a bit confused about the purpose of it. Mainly I was wondering if we could drop LangAS parameters from it? It would simplify its use a lot in multiple places. As far as I can see they are not used in the function at the moment. I am not sure if they are reserved for some development in the future though?

Altogether I quite like using IRBuilder directly because in combination with target address space map it allows to do what's needed here and keep consistent with the rest. Perhaps, I am missing some background info. I have tried to dig out a bit but no much success.

rjmccall added inline comments.Feb 25 2019, 9:42 PM
lib/CodeGen/CGCall.cpp
4067 ↗(On Diff #188206)

We want to allow language address spaces to be arbitrarily mapped to IR address spaces during lowering, which might include e.g. changing the null value. That's why we pass language address spaces down.

You should be getting the language address space from the appropriate type. I wouldn't expect that to include address-space conversions at this point, though; is there maybe a missing implicit conversions somewhere?

Anastasia marked an inline comment as done.Feb 26 2019, 4:10 AM
Anastasia added inline comments.
lib/CodeGen/CGCall.cpp
4067 ↗(On Diff #188206)

We want to allow language address spaces to be arbitrarily mapped to IR address spaces during lowering, which might include e.g. changing the null value. That's why we pass language address spaces down.

Would this mean we can map AST address spaces into different IR ones from what is the the target address space map? Ok right, null pointer value can't be handled by the target address space map at all. I am a bit confused though why we are not using these LangAS at the moment. I guess we just don't have upstream targets requiring that...

is there maybe a missing implicit conversions somewhere?

Ok, the AST dump doesn't seem right for the test case I included. MaterializeTemporaryExpr is in generic addr space. I guess it should be private... and then converted to generic.

`-FunctionDecl 0x712608 <line:5:1, line:11:1> line:5:6 foo 'void ()'
  `-CompoundStmt 0x712810 <col:11, line:11:1>
    `-ExprWithCleanups 0x7127f8 <line:10:3, col:8> 'int'
      `-CallExpr 0x7127a0 <col:3, col:8> 'int'
        |-ImplicitCastExpr 0x712788 <col:3> 'int (*)(const __generic unsigned int &)' <FunctionToPointerDecay>
        | `-DeclRefExpr 0x712710 <col:3> 'int (const __generic unsigned int &)' lvalue Function 0x7124d0 'bar' 'int (const __generic unsigned int &)'
        `-MaterializeTemporaryExpr 0x7127e0 <col:7> 'const __generic unsigned int' lvalue
          `-ImplicitCastExpr 0x7127c8 <col:7> 'const __generic unsigned int' <IntegralCast>
            `-IntegerLiteral 0x7126f0 <col:7> 'int' 1

I will fix it!

Anastasia updated this revision to Diff 189313.Mar 5 2019, 6:41 AM
  • Implement the fix correctly by added an extra address space conversion step after binding the reference
rjmccall accepted this revision.Mar 5 2019, 8:31 AM

This test file will probably grow over time, so please add a CHECK-LABEL line to the test case to make sure you're checking the body of foo(). Also, you'll probably need to allow the name %ref.tmp to be stripped for this test to pass in release builds; please go ahead and test a more complete pattern, including the alloca and the store of 1 to it. Otherwise LGTM.

This revision is now accepted and ready to land.Mar 5 2019, 8:31 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2019, 5:01 AM