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

2020-03-04 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment. In D75285#1903611 , @yaxunl wrote: > In D75285#1903444 , @rjmccall wrote: > > > That is not true for two reasons: first, `restrict` guarantees that the > > variable is not accessed throug

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

2020-03-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment. In D75285#1903611 , @yaxunl wrote: > In D75285#1903444 , @rjmccall wrote: > > > That is not true for two reasons: first, `restrict` guarantees that the > > variable is not accessed through

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

2020-03-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. In D75285#1903444 , @rjmccall wrote: > That is not true for two reasons: first, `restrict` guarantees that the > variable is not accessed through any non-derived l-value within its scope, > and that would certainly include from ot

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

2020-03-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment. In D75285#1903284 , @yaxunl wrote: > In D75285#1902835 , > @jeroen.dobbelaere wrote: > > > In D75285#1902788 , @Anastasia > > wrote: > > > > > In

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

2020-03-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. In D75285#1902835 , @jeroen.dobbelaere wrote: > In D75285#1902788 , @Anastasia wrote: > > > In D75285#1896610 , @rjmccall > > wrote: > > > > > Are y

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

2020-03-03 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere added a comment. In D75285#1902788 , @Anastasia wrote: > In D75285#1896610 , @rjmccall wrote: > > > Are you sure `restrict` alone isn't good enough? It doesn't directly tell > > you that the memo

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

2020-03-03 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment. In D75285#1896610 , @rjmccall wrote: > Are you sure `restrict` alone isn't good enough? It doesn't directly tell > you that the memory is invariant, but it's usually simple to prove that the > memory isn't modified within the

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

2020-02-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. In D75285#1897502 , @jeroen.dobbelaere wrote: > I don't think that 'restrict' is a good match for this behavior. For c++, the > alias_set proposal > (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4150.pdf) would be >

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

2020-02-28 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added a comment. In D75285#1897502 , @jeroen.dobbelaere wrote: > I don't think that 'restrict' is a good match for this behavior. For c++, the > alias_set proposal > (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4150.pdf) would be >

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

2020-02-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment. In D75285#1897537 , @JonChesterfield wrote: > In D75285#1897247 , @yaxunl wrote: > > > If users derive a non-const pointer from the const pointer and modify it, > > doesn't that result in

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

2020-02-28 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment. In D75285#1897247 , @yaxunl wrote: > If users derive a non-const pointer from the const pointer and modify it, > doesn't that result in UB? Thanks. No. Modifying a const object is UB, so e.g. we can segv if it's in .roda

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

2020-02-28 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere added a comment. I don't think that 'restrict' is a good match for this behavior. For c++, the alias_set proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4150.pdf) would be a better match. You would put the read access of *p in its own universe; or even bette

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

2020-02-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. In D75285#1896458 , @rjmccall wrote: > Unfortunately, `const` also doesn't mean that the memory doesn't change. It > does mean it can't be changed through this pointer, but `restrict` allows you > to derive more pointers from it

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

2020-02-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. In D75285#1896400 , @hfinkel wrote: > 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 wo

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

2020-02-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment. Are you sure `restrict` alone isn't good enough? It doesn't directly tell you that the memory is invariant, but it's usually simple to prove that the memory isn't modified within the `restrict` scope, which might be sufficient. CHANGES SINCE LAST ACTION https://rev

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

2020-02-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment. If this is not the right way to tell the compiler a memory pointed to by a pointer is invariant, what is the recommended way? Can we introduce clang builtins for llvm.invariant.start and llvm.invariant.end to allow user to specify that? Thanks. CHANGES SINCE LAST ACTI

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

2020-02-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment. Unfortunately, `const` also doesn't mean that the memory doesn't change. It does mean it can't be changed through this pointer, but `restrict` allows you to derive more pointers from it within the `restrict` scope, and those pointers can remove the `const` qualifier.

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

2020-02-27 Thread Hal Finkel via Phabricator via cfe-commits
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 th

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

2020-02-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision. yaxunl added a reviewer: rjmccall. We saw users intend to use `const int* restrict` to indicate the memory pointed to by the pointer is invariant. This makes sense since restrict means the memory is not aliased by any other pointers whereas const means the memory d