Hi,

On FreeBSD 12.0/x86, the newest release m4-1.4.18 and the newest snapshot
from https://gitlab.com/gnu-m4/ci-distcheck/ both exhibit a "make check"
failure:

Checking ../../checks/189.eval
@ ../doc/m4.texi:6405: Origin of test
../../checks/189.eval: stdout mismatch
--- m4-tmp.17036/m4-xout        2020-05-03 02:14:13.289357000 +0200
+++ m4-tmp.17036/m4-out 2020-05-03 02:14:13.279345000 +0200
@@ -2,8 +2,8 @@
 
 1
 1
-overflow occurred
--2147483648
+
+2147483648
 0
 -2
 -2

...

Failed checks were:
  ../../checks/189.eval:out
*** Error code 1

Simplified test case:
$ cat > in <<EOF
define(`max_int', eval(`0x7fffffff'))
define(`min_int', incr(max_int))
min_int
EOF
$ m4 < in

Expected output:


-2147483648

Actual output on FreeBSD:


2147483648

The bug occurs if and only if the source file builtin.c is compiled with
optimization -O2 or higher.

The attached patch (for the 'branch-1.4' branch) fixes the issue.

Bruno
>From aaa68d60ab6c84783cf050a9e43aa6f40c81e4df Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 3 May 2020 03:00:46 +0200
Subject: [PATCH] Work around a compiler optimization bug on FreeBSD 12.0.

* src/builtin.c (ntoa): Declare value parameter as 'volatile'.
---
 src/builtin.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/builtin.c b/src/builtin.c
index 4eaccc6..988cc93 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1,6 +1,6 @@
 /* GNU m4 -- A simple macro processor
 
-   Copyright (C) 1989-1994, 2000, 2004, 2006-2014, 2016-2017 Free
+   Copyright (C) 1989-1994, 2000, 2004, 2006-2014, 2016-2017, 2020 Free
    Software Foundation, Inc.
 
    This file is part of GNU M4.
@@ -449,8 +449,9 @@ numeric_arg (token_data *macro, const char *arg, int *valuep)
 /* Digits for number to ASCII conversions.  */
 static char const digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 
+/* The 'volatile' neutralizes a clang 6.0.1 optimization bug.  */
 const char *
-ntoa (int32_t value, int radix)
+ntoa (int32_t volatile value, int radix)
 {
   bool negative;
   uint32_t uvalue;
-- 
2.7.4

Reply via email to