This patch introduces a warning for undefined behavior introduced by assignments to a restrict-qualified pointer an expression based on other restrict qualified pointers. Roughly speaking, this happens when the LHS is designated by an identifier with a scope contained by the scope of the RHS designator (you can't assign from an "inner" restrict pointer to an "outer" one -- or between two at the same level).
For example, if we have:
struct S { int * restrict x; int * restrict y; }; void f6(int * restrict q1, int * restrict q2, struct S s, struct S *t) { s.x = q1; t->y = s.x; }
you'll get these warnings (with some hopefully-useful notes):
warning: assignment to a restrict-qualified pointer designated by 's' using an expression based on a restrict-qualified pointer designated by 'q1' has undefined behavior [-Wundefined-restrict-assignment] s.x = q1; ^ note: the block associated with 'q1', declared here void f6(int * restrict q1, int * restrict q2, struct S s, struct S *t) ^ note: does not begin before the block associated with 's', declared here void f6(int * restrict q1, int * restrict q2, struct S s, struct S *t) ^ warning: assignment to a restrict-qualified pointer designated by 't' using an expression based on a restrict-qualified pointer designated by 's' has undefined behavior [-Wundefined-restrict-assignment] t->y = s.x; ^ note: the block associated with 's', declared here void f6(int * restrict q1, int * restrict q2, struct S s, struct S *t) ^ note: does not begin before the block associated with 't', declared here void f6(int * restrict q1, int * restrict q2, struct S s, struct S *t) ^
Currently, this only determines the "based on" relationship via a syntactic analysis of the expression. In the future, I'd like to make this an analysis-based warning so that some data-flow information can inform the "based on" determination in case it flows through other non-restrict-qualified pointers.
Thanks again!
I don't think this is what you mean. Linkage is not relevant to the restrict rules as far as I can see; I think you're trying to check the storage class here. Maybe VarDecl::hasGlobalStorage() is what you want?