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!
Maybe also test that casts to the same address space are accepted?