You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extern"C"{fnprintf(s:*consti8, ...);}#[lang = "add_assign"]pubtraitAddAssign<Rhs = Self>{fnadd_assign(&mutself,rhs:Rhs);}implAddAssignfori32{fnadd_assign(&mutself,other:i32){unsafe{let a = "add_assign\n\0";let b = a as*conststr;let c = b as*consti8;printf(c);}*self += other
}}fnmain() -> i32{letmut a = 1;
a += 2;0}
I expected to see this happen: The address is taken on the VAR_DECL not an implicit temporary
Instead, this happened: TREE_ADDRESSABLE is false on 'a' and is required to stop the implicit copy
814: Set TREE_ADDRESSABLE when we need to borrow any expression r=philberty a=philberty
GCC requires VAR_DECL's and PARAM_DECL's to be marked with TREE_ADDRESSABLE
when the declaration will be used in borrow's ('&' getting the address).
This takes into account the implicit addresses when we do autoderef in
method resolution/operator-overloading.
If it is not set we end up in cases like this:
```c
i32 main ()
{
i32 a.1;
i32 D.86;
i32 a;
a = 1;
a.1 = a; // this is wrong
<i32 as AddAssign>::add_assign (&a.1, 2);
D.86 = 0;
return D.86;
}
```
You can see GCC will automatically make a copy of the VAR_DECL resulting bad code-generation.
Fixes#804
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
I tried this code:
I expected to see this happen: The address is taken on the VAR_DECL not an implicit temporary
Instead, this happened: TREE_ADDRESSABLE is false on 'a' and is required to stop the implicit copy
Meta
The text was updated successfully, but these errors were encountered: