> Am 13.02.2024 um 16:27 schrieb Ties Klappe via Gcc <gcc@gcc.gnu.org>:
> 
> Thank you both for your quick replies.
> 
> @Joseph, thank you for linking me to the other issue. If I understand
> correctly what the point is, would you then agree that the program main
> when calling foo2 has *defined* behavior?
> What surprises me is that *p and *q might be the same restricted pointer:
> the *xp* object itself is not declared as *int** *restrict* but as *int**.
> 
> By passing *xp* as argument to foo1, is the type of the object *xp* then
> implicitly converted to (or merely interpreted as) *int* restrict *(because
> of the argument type)*, i.e.* xp corresponds to the object *P *the standard
> refers to?
> 
> int main() {
>    int x = 0;
>    int* xp = &x;
> 
>    int res = foo2(&xp, &xp);
> 
>    return 0;
> }
> 
> ---
> 
> @Richard, thank you for the alternative implementation. Is foo3 meant to be
> optimized by GCC currently (I didn't manage to get GCC13.2 to do it)? Or is
> it a hypothetical example that would allow GCC to optimize it?

It’s a situation to show handling your two examples the same would be difficult.

> int foo3(int *restrict * p, int *restrict * q)
> {
>    int a;
>    *p = &a;
>    **q = 11;
>    **p = 12;
>    return **q;
> }
> 
> Kind regards,
> Ties
> 
> 
> Op di 13 feb 2024 om 15:29 schreef Joseph Myers <josmy...@redhat.com>:
> 
>>> On Tue, 13 Feb 2024, Ties Klappe via Gcc wrote:
>>> 
>>> int foo2(int *restrict *p, int *restrict *q)
>>> {
>>>    **p = 10;
>>>    **q = 11;
>>>    return **p;
>>> }
>> 
>> In this case, *p and *q might be the same restricted pointer object.  See
>> the more detailed explanation at
>> <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14192#c8>.
>> 
>> --
>> Joseph S. Myers
>> josmy...@redhat.com
>> 
>> 

Reply via email to