On 2023-12-01 21:52, Bruno Haible wrote:
There is nothing wrong with this code (m4/frexp.m4:159, m4/frexpf.m4:83).

Isn't there? I thought that the C standard doesn't let you access a 'double volatile' object via a 'void *' or 'void const *' pointer. It'd need to be 'void volatile *' or 'void const volatile *'.


We don't want to add a cast here, because — as Paul argues — casts can make
code more difficult to maintain in the long run.

We can conform to standard C without a cast with something like the attached (which I haven't installed).

(I assume the 'volatile' is there because of the funky things compilers do with x86 double....)
From 006cf2337a8ca2e3a0b41c488fbe3d95eda201f3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 1 Dec 2023 22:19:22 -0800
Subject: [PATCH] frexp: pacify clang re address-of-volatile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Sam James in:
https://lists.gnu.org/r/bug-gnulib/2023-12/msg00013.html
* m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Don’t try to convert
‘double volatile *’ to ‘void const *’ as the C standard
doesn’t allow accessing volatile variables through
pointer-to-nonvolatile.
---
 ChangeLog   | 8 ++++++++
 m4/frexp.m4 | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c713de7b42..f30430d3de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2023-12-01  Paul Eggert  <egg...@cs.ucla.edu>
 
+	frexp: pacify clang re address-of-volatile
+	Problem reported by Sam James in:
+	https://lists.gnu.org/r/bug-gnulib/2023-12/msg00013.html
+	* m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Don’t try to convert
+	‘double volatile *’ to ‘void const *’ as the C standard
+	doesn’t allow accessing volatile variables through
+	pointer-to-nonvolatile.
+
 	Update portability doc for CHERI, C23
 	* doc/gnulib-readme.texi:
 	Prefer “null pointer” to “@code{NULL}” since C23 has nullptr.
diff --git a/m4/frexp.m4 b/m4/frexp.m4
index 0293765c59..b23aa470c3 100644
--- a/m4/frexp.m4
+++ b/m4/frexp.m4
@@ -1,4 +1,4 @@
-# frexp.m4 serial 18
+# frexp.m4 serial 19
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -156,7 +156,8 @@ int main()
   {
     int exp;
     double y = frexp (x, &exp);
-    if (memcmp (&y, &x, sizeof x))
+    double x1 = x;
+    if (memcmp (&y, &x1, sizeof x1))
       result |= 4;
   }
   return result;
-- 
2.40.1

Reply via email to