RESOLVED FIXED 198198
[WHLSL] Make sure we properly emit code for "&*x"
https://bugs.webkit.org/show_bug.cgi?id=198198
Summary [WHLSL] Make sure we properly emit code for "&*x"
Saam Barati
Reported 2019-05-23 15:16:08 PDT
...
Attachments
patch (10.62 KB, patch)
2019-05-31 01:56 PDT, Saam Barati
no flags
Saam Barati
Comment 1 2019-05-23 15:16:54 PDT
int foo(thread Bar* bar) { return bar->x; } turns into int foo(thread Bar* bar) { return *operator&.x(&*bar); } the "&*bar" is suspect.
Myles C. Maxfield
Comment 2 2019-05-23 15:32:22 PDT
Yeah, the parser turns bar->x into (*bar).x, then the property resolver reduces the dot expression via the ander. The ander requires a pointer, so we get one by calling &. The checker detects that (*bar) is an lvalue, so we think it's legal to say &(*bar)
Saam Barati
Comment 3 2019-05-23 16:06:02 PDT
Actually, after Robin and Myles thought about it, it seems like it's correct. "*x" is an lvalue if x is an lvalue. I guess we sort of need to treat "*x" like C++ treats references. Not sure how far this will extend in terms of implementation. But there's a chance all we need is an AST rewrite rule since we can't variables with reference types.
Saam Barati
Comment 4 2019-05-23 16:06:32 PDT
As Myles suggested, a good test would be &*p == p => true
Myles C. Maxfield
Comment 5 2019-05-23 16:30:17 PDT
One way to do this would be a pass that cancels out adjacent & and * operators. But that may not be sufficient.
Myles C. Maxfield
Comment 6 2019-05-24 09:36:48 PDT
For &*x, the emitted Metal code right now will be auto temp = *x; auto temp2 = &temp; Which is wrong. Perhaps we could modify the Metal codegen to instead emit auto& temp = *x; auto temp2 = &temp;
Myles C. Maxfield
Comment 7 2019-05-24 09:40:45 PDT
If we take this approach, it may actually solve https://bugs.webkit.org/show_bug.cgi?id=197448. *x = 4; Would get compiled to auto& temp = *x; temp = 4; Which I think is correct
Saam Barati
Comment 8 2019-05-24 09:58:40 PDT
(In reply to Myles C. Maxfield from comment #7) > If we take this approach, it may actually solve > https://bugs.webkit.org/show_bug.cgi?id=197448. > > *x = 4; > > Would get compiled to > > auto& temp = *x; > temp = 4; > > Which I think is correct Looks like it’d be correct. Though we’d need to make sure to selectively emit references since I’m assuming “auto& temp = 42” is invalid metal
Saam Barati
Comment 9 2019-05-24 09:59:28 PDT
(In reply to Saam Barati from comment #8) > (In reply to Myles C. Maxfield from comment #7) > > If we take this approach, it may actually solve > > https://bugs.webkit.org/show_bug.cgi?id=197448. > > > > *x = 4; > > > > Would get compiled to > > > > auto& temp = *x; > > temp = 4; > > > > Which I think is correct > > Looks like it’d be correct. Though we’d need to make sure to selectively > emit references since I’m assuming “auto& temp = 42” is invalid metal Oooh. I think you mean just for dereference nodes!
Saam Barati
Comment 10 2019-05-31 01:56:40 PDT
Myles C. Maxfield
Comment 11 2019-05-31 09:12:13 PDT
*** Bug 197448 has been marked as a duplicate of this bug. ***
WebKit Commit Bot
Comment 12 2019-05-31 11:16:51 PDT
Comment on attachment 371046 [details] patch Clearing flags on attachment: 371046 Committed r245973: <https://trac.webkit.org/changeset/245973>
WebKit Commit Bot
Comment 13 2019-05-31 11:16:52 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 14 2019-05-31 11:17:22 PDT
Note You need to log in before you can comment on or make changes to this bug.