Open dobbelaj-snps opened 5 years ago
- llvm + Hal Finkels local restrict patches has the correct behavior, IF the restrict is made local
Interesting test case. We could easily change this to also work for the function-argument case, and it looks like we may need to do just that.
Extended Description
clang/llvm implements argument restrictness by putting a
noalias
on the the restrict argument. When alias analysis traces the base object of a pointer to two different base objects of which one is marked withnoalias
, it concludes that these pointers do not alias.This mapping results in wrong behavior according to the restrict specification: (or my interpretation of it is wrong ;) ):
where P is the restrict annotated pointer. This means that in following code tmp and pA might alias:
results in:
But, clang/llvm assumes that tmp and pA will never alias, and propagates the 42.
NOTES:
__restrict
frompA
to thepC
argument, results in equivalent code with the correct behavior.results in: