AhmedKamel10 wrote:

Hi @ojhunt . Not sure if you meant to loop me in too, but I wanted to add a bit 
of context.
The main example I could think of for a safe write is memoization, where a pure 
function caches its result in a static local. It goes something like this:

```c
int compute(int x) __attribute__((pure));
int compute(int x) {
  static int last_x = -1, last_result = 0;
  if (x == last_x) return last_result;
  last_result = expensive(x);
  last_x = x;
  return last_result;
}
```
The checker would warn on the writes to the static variables. I can see how 
this could be safe since the cache isn't visible outside the function, even 
though it technically doesn't follow the pure contract.
Since the warning is opt-in, I thought this might be an acceptable tradeoff, 
but idk if what you had in mind when you mentioned "semantically safe" writes 
is a different case I can't think of.





https://github.com/llvm/llvm-project/pull/217817
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to