This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Disallow casting between address spaces
ClosedPublic

Authored by joey on Jan 9 2014, 5:47 AM.

Details

Reviewers
rsmith
Summary

Clang can currently diagnose the following code:
global int *g = l; // expected-error {{casting 'local int *' to type 'global int *' changes address space of pointer}}

However it does not diagnose:
global int *g = (global int*) l; // expected-error {{casting 'local int *' to type 'global int *' changes address space of pointer}}

The attached patch now errors for this second piece of code. However, I had to add code to CheckCStyleCast, I could not figure out if it was possible to get it to be diagnosed by Sema::DiagnoseAssignmentResult, which handles the first case.

ps: note that the error message shows "__global", when I actually wrote "global". I'd like to fix that too at some point!

Diff Detail

Event Timeline

rsmith accepted this revision.Jan 10 2014, 6:49 PM

LGTM

test/SemaOpenCL/address-spaces.cl
15

Maybe also test that casts to the same address space are accepted?

Eugene.Zelenko closed this revision.Oct 4 2016, 4:24 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in rL199208.