bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] attribute: const/pure defaults to unsequenced/reproducible


From: Paul Eggert
Subject: Re: [PATCH] attribute: const/pure defaults to unsequenced/reproducible
Date: Wed, 5 Jun 2024 11:59:32 -0700
User-agent: Mozilla Thunderbird

On 2024-06-05 08:32, Basil L. Contovounesios wrote:

It's also too bad that N2956 has this typo, and that it doesn't mention
GCC's returns-exactly-once constraints on pure and const functions.

Do you have a pointer to where this constraint is documented?  I'm not
sure what it means, and I can't find it in my copy of the gcc-13 manual.

It's not stated directly, but it's there. It should be documented better. I've confirmed it by compiling programs and looking at the code, and via messages from GCC implementers.

For example, compile this with 'gcc -O2 -S':

  int difftime (long, long) __attribute__ ((pure));

  int
  f ()
  {
    return difftime (42, 27) - difftime (42, 27);
  }

and you'll see that the calls to difftime are optimized away and f always returns 0. This optimization would be invalid if difftime did not return, or returned multiple times.

The C23 spec for [[unsequenced]] and [[reproducible]] does not mention this issue, which is a significant oversight.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]