On 03/05/2018 12:48 PM, John Wiersba wrote:
I'm not sure of the rationale for using enum here, but apparently the AIX xlC 
compiler
doesn't like it.

That's a bug in the IBM xlC compiler; could you please report it to IBM?

The code uses an enum because it wants to name the expression. The C standard requires that static array sizes have constant bounds, and enums are constants, so this technique conforms to C89 (as well as to C99 and C11). If the IBM compiler is complaining about it then it's not conforming to the standard. Most likely the compiler is incorrectly hoisting the static decl to be as if it were outside the function body, which is an incorrect transformation.

Anyway, I installed the attached patch into coreutils, to work around the compiler bug. Thanks for reporting the problem.


>From 6d0989816d0e3c26dd90c50bd63040293d2b7f7a Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 5 Mar 2018 15:50:39 -0800
Subject: [PATCH] stat: work around IBM xlC bug

Problem reported by John Wiersba (Bug#30718)
* src/stat.c (human_time): Avoid giving an integer constant
expression a name, as it runs afoul of a bug in IBM XL C/C++ for
AIX 12.01.0000.0002.
---
 src/stat.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/stat.c b/src/stat.c
index 8614a4d11..c5da60260 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -590,12 +590,10 @@ human_access (struct stat const *statbuf)
 static char * ATTRIBUTE_WARN_UNUSED_RESULT
 human_time (struct timespec t)
 {
-  /* STR must be at least this big, either because localtime_rz fails,
-     or because the time zone is truly outlandish so that %z expands
-     to a long string.  */
-  enum { intmax_bufsize = INT_BUFSIZE_BOUND (intmax_t) };
-
-  static char str[intmax_bufsize
+  /* STR must be at least INT_BUFSIZE_BOUND (intmax_t) big, either
+     because localtime_rz fails, or because the time zone is truly
+     outlandish so that %z expands to a long string.  */
+  static char str[INT_BUFSIZE_BOUND (intmax_t)
                   + INT_STRLEN_BOUND (int) /* YYYY */
                   + 1 /* because YYYY might equal INT_MAX + 1900 */
                   + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"];
-- 
2.14.3

Reply via email to