[PATCH] D75285: Mark restrict pointer or reference to const as invariant

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 12:23:27 PST 2020


hfinkel requested changes to this revision.
hfinkel added a comment.
This revision now requires changes to proceed.

Unfortunately, we cannot do this kind of thing just because it seems to make sense. The language semantics must be exactly satisfied by the IR-level semantics. I certainly agree that it would make sense for users to be able to mark invariant loads, but this mechanism simply might not be the right one.

One problem here is that, with something like:

  char test2(X *x) {
    const char* __restrict p = &(x->b);
    return *p;
  }

what happens when the function is inlined? Does the "invariantness" only still apply to accesses within the scope of the local restrict pointer? I believe that it would not, and that would be a problem because later code might legally modify the relevant data.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75285/new/

https://reviews.llvm.org/D75285





More information about the cfe-commits mailing list