diff mbox series

[1/2] difftime can throw exceptions

Message ID 20240528172615.1397454-2-eggert@cs.ucla.edu
State New
Headers show
Series difftime isn't even pure | expand

Commit Message

Paul Eggert May 28, 2024, 5:26 p.m. UTC
difftime can signal an inexact conversion when converting to double,
so it should not be marked as pure or nothrow (BZ 31808).

Although we could do something more complicated, in which difftime is
plain on modern platforms but const and nothrow on obsolescent
platforms with 32-bit time_t, it hardly seems worth the trouble.
difftime is used so rarely that it's not worth taking pains to
optimize calls to it on obsolescent platforms.
---
 time/time.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Florian Weimer June 4, 2024, 4:42 p.m. UTC | #1
* Paul Eggert:

> difftime can signal an inexact conversion when converting to double,
> so it should not be marked as pure or nothrow (BZ 31808).

At the GCC level, throwing from a signal handler inside is only
supported if building with -fnon-call-exceptions.  Is anyone actually
doing that?

Thanks,
Florian
Paul Eggert June 4, 2024, 7:33 p.m. UTC | #2
On 2024-06-04 09:42, Florian Weimer wrote:

> At the GCC level, throwing from a signal handler inside is only
> supported if building with -fnon-call-exceptions.  Is anyone actually
> doing that?

A quick search suggests that some people do it, yes. For example:

https://github.com/golang/gofrontend/blob/60f985a7852632834936b4b859aa75d9df88f038/libgo/Makefile.am#L49

https://github.com/LibreOffice/core/blob/d6607a9d9a3076c1d7c9a3e284631c5f57c24137/bridges/Library_cpp_uno.mk#L241

https://forums.zeroc.com/discussion/46747/problem-linking-to-debug-libraries-on-rh7

I didn't check whether any of these people also use difftime.
Florian Weimer June 4, 2024, 8:52 p.m. UTC | #3
* Paul Eggert:

> On 2024-06-04 09:42, Florian Weimer wrote:
>
>> At the GCC level, throwing from a signal handler inside is only
>> supported if building with -fnon-call-exceptions.  Is anyone actually
>> doing that?
>
> A quick search suggests that some people do it, yes. For example:
>
> https://github.com/golang/gofrontend/blob/60f985a7852632834936b4b859aa75d9df88f038/libgo/Makefile.am#L49
>
> https://github.com/LibreOffice/core/blob/d6607a9d9a3076c1d7c9a3e284631c5f57c24137/bridges/Library_cpp_uno.mk#L241
>
> https://forums.zeroc.com/discussion/46747/problem-linking-to-debug-libraries-on-rh7

Yes, it's heavily exercised by the Ada front end.

But what I meant: The code that throws from a synchronously invoked
signal handler would have to be built with -fnon-call-exceptions, so in
our case, glibc.

Thanks,
Florian
Paul Eggert June 4, 2024, 10:53 p.m. UTC | #4
On 6/4/24 13:52, Florian Weimer wrote:
> But what I meant: The code that throws from a synchronously invoked
> signal handler would have to be built with -fnon-call-exceptions, so in
> our case, glibc.

Oh, in that case, no I don't know of anybody doing that.

We could document that one cannot build glibc with -fnon-call-exceptions 
(and similarly for -flto and other options you can't build glibc with), 
and then bring back __attribute__ ((pure)) for difftime. But we couldn't 
bring back __attribute__ ((const)) due to rounding mode changes, right?

Not sure it's worth the effort just for the rarely-used difftime, but it 
might be worth it if more commonly-used library calls benefit from these 
attributes.
diff mbox series

Patch

diff --git a/time/time.h b/time/time.h
index 486367f7dd..b6b439a452 100644
--- a/time/time.h
+++ b/time/time.h
@@ -76,8 +76,7 @@  extern clock_t clock (void) __THROW;
 extern time_t time (time_t *__timer) __THROW;
 
 /* Return the difference between TIME1 and TIME0.  */
-extern double difftime (time_t __time1, time_t __time0)
-     __THROW __attribute_pure__;
+extern double difftime (time_t __time1, time_t __time0);
 
 /* Return the `time_t' representation of TP and normalize TP.  */
 extern time_t mktime (struct tm *__tp) __THROW;
@@ -85,7 +84,7 @@  extern time_t mktime (struct tm *__tp) __THROW;
 # ifdef __REDIRECT_NTH
 extern time_t __REDIRECT_NTH (time, (time_t *__timer), __time64);
 extern double __REDIRECT_NTH (difftime, (time_t __time1, time_t __time0),
-                              __difftime64) __attribute_pure__;
+                              __difftime64);
 extern time_t __REDIRECT_NTH (mktime, (struct tm *__tp), __mktime64);
 # else
 #  define time __time64