Daniel Richard G. wrote:

This recent change to fnmatch.c breaks the build on z/OS:

DEPDIR=.deps depmode=aix /bin/sh /u/darkstar/testdir/build-aux/depcomp \
xlc-wrap -DHAVE_CONFIG_H -I. -I/u/darkstar/testdir/gllib -I..  
-DGNULIB_STRICT_CHECKING=1 -D_XOPEN_SOURCE=600 -DNSIG=39 -qhaltonmsg=CCN3296  
-g -qfloat=ieee -qlanglvl=extc99  -c -o fnmatch.o 
/u/darkstar/testdir/gllib/fnmatch.c
ERROR CCN3046 /usr/include/builtins.h:1858  Syntax error.
CCN0793(I) Compilation failed for file /u/darkstar/testdir/gllib/fnmatch.c.  
Object file not created.
make[4]: *** [fnmatch.o] Error 12

As far as I can tell, __builtin_expect() is not a preprocessor symbol on
this platform:

No, it's a compiler builtin. I installed the attached to gnulib; please give it a try.
>From fd5b6938311028bb36a9792d2f7cc90eda61f626 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 16 Dec 2016 14:52:59 -0800
Subject: [PATCH] builtin-expect: new module

Fix fnmatch to use it.
Problem reported for z/OS by Daniel Richard G.
* lib/fnmatch.c (__builtin_expect):
* lib/glob.c (__builtin_expect):
* lib/grantpt.c (__builtin_expect) [!_LIBC]:
* lib/memmem.c (__builtin_expect) [!_LIBC]:
* lib/scandir.c (__builtin_expect):
* lib/strstr.c (__builtin_expect) [!_LIBC]:
Remove macro; config.h now does this.
* lib/gl_anytreehash_list1.h (add_to_bucket):
* lib/regex_internal.h (BE):
Assume __builtin_expect.
* m4/builtin-expect.m4, modules/builtin-expect: New files.
* modules/avltreehash-list, modules/fnmatch, modules/glob:
* modules/grantpt, modules/memmem-simple, modules/rbtreehash-list:
* modules/scandir, modules/strstr-simple:
Depend on builtin-expect.
---
 ChangeLog                  | 21 +++++++++++++++++++++
 lib/fnmatch.c              |  4 ----
 lib/gl_anytreehash_list1.h |  4 +---
 lib/glob.c                 |  4 ----
 lib/grantpt.c              |  1 -
 lib/memmem.c               |  4 ----
 lib/regex_internal.h       |  6 +-----
 lib/scandir.c              |  4 ----
 lib/strstr.c               |  4 ----
 m4/builtin-expect.m4       | 34 ++++++++++++++++++++++++++++++++++
 modules/avltreehash-list   |  1 +
 modules/builtin-expect     | 20 ++++++++++++++++++++
 modules/fnmatch            |  1 +
 modules/glob               |  1 +
 modules/grantpt            |  1 +
 modules/memmem-simple      |  1 +
 modules/rbtreehash-list    |  1 +
 modules/scandir            |  2 +-
 modules/strstr-simple      |  1 +
 19 files changed, 85 insertions(+), 30 deletions(-)
 create mode 100644 m4/builtin-expect.m4
 create mode 100644 modules/builtin-expect

diff --git a/ChangeLog b/ChangeLog
index f3522e7..451e1d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2016-12-16  Paul Eggert  <egg...@cs.ucla.edu>
+
+	builtin-expect: new module
+	Fix fnmatch to use it.
+	Problem reported for z/OS by Daniel Richard G.
+	* lib/fnmatch.c (__builtin_expect):
+	* lib/glob.c (__builtin_expect):
+	* lib/grantpt.c (__builtin_expect) [!_LIBC]:
+	* lib/memmem.c (__builtin_expect) [!_LIBC]:
+	* lib/scandir.c (__builtin_expect):
+	* lib/strstr.c (__builtin_expect) [!_LIBC]:
+	Remove macro; config.h now does this.
+	* lib/gl_anytreehash_list1.h (add_to_bucket):
+	* lib/regex_internal.h (BE):
+	Assume __builtin_expect.
+	* m4/builtin-expect.m4, modules/builtin-expect: New files.
+	* modules/avltreehash-list, modules/fnmatch, modules/glob:
+	* modules/grantpt, modules/memmem-simple, modules/rbtreehash-list:
+	* modules/scandir, modules/strstr-simple:
+	Depend on builtin-expect.
+
 2016-12-15  Bruno Haible  <br...@clisp.org>
 
 	init.sh: Add possibility to not delete temporary files.
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 75b85c0..cc690bb 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -22,10 +22,6 @@
 # define _GNU_SOURCE    1
 #endif
 
-#if ! defined __builtin_expect && (!defined __GNUC__ || __GNUC__ < 3)
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #include <fnmatch.h>
 
 #include <alloca.h>
diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h
index 11578ed..cf44b59 100644
--- a/lib/gl_anytreehash_list1.h
+++ b/lib/gl_anytreehash_list1.h
@@ -185,10 +185,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
   return 0;
 }
 /* Tell GCC that the likely return value is 0.  */
-#if __GNUC__ >= 3
-# define add_to_bucket(list,node) \
+#define add_to_bucket(list,node) \
     __builtin_expect ((add_to_bucket) (list, node), 0)
-#endif
 
 /* Remove a node from the hash table structure.
    If duplicates are allowed, this function performs in average time
diff --git a/lib/glob.c b/lib/glob.c
index 5b2ff9d..4a7dab2 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -222,10 +222,6 @@ convert_dirent64 (const struct dirent64 *source)
 # endif
 #endif
 
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #ifndef __glibc_unlikely
 # define __glibc_unlikely(expr) __builtin_expect (expr, 0)
 #endif
diff --git a/lib/grantpt.c b/lib/grantpt.c
index e4c1b91..2af879a 100644
--- a/lib/grantpt.c
+++ b/lib/grantpt.c
@@ -35,7 +35,6 @@
 #include "pty-private.h"
 
 #ifndef _LIBC
-# define __builtin_expect(expr,val) (expr)
 # define __set_errno(e) errno = (e)
 # define __dup2 dup2
 # define __fork fork
diff --git a/lib/memmem.c b/lib/memmem.c
index 255490e..a77c107 100644
--- a/lib/memmem.c
+++ b/lib/memmem.c
@@ -24,10 +24,6 @@
 /* Specification of memmem.  */
 #include <string.h>
 
-#ifndef _LIBC
-# define __builtin_expect(expr, val)   (expr)
-#endif
-
 #define RETURN_TYPE void *
 #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
 #include "str-two-way.h"
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 7ac5f92..4114107 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -115,11 +115,7 @@
 # define RE_ENABLE_I18N
 #endif
 
-#if __GNUC__ >= 3
-# define BE(expr, val) __builtin_expect (expr, val)
-#else
-# define BE(expr, val) (expr)
-#endif
+#define BE(expr, val) __builtin_expect (expr, val)
 
 /* Number of ASCII characters.  */
 #define ASCII_CHARS 0x80
diff --git a/lib/scandir.c b/lib/scandir.c
index a41ef1a..747bd87 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -26,10 +26,6 @@
 # include <bits/libc-lock.h>
 #endif
 
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #undef select
 
 #ifndef _D_EXACT_NAMLEN
diff --git a/lib/strstr.c b/lib/strstr.c
index 7e1865f..29da790 100644
--- a/lib/strstr.c
+++ b/lib/strstr.c
@@ -26,10 +26,6 @@
 
 #include <stdbool.h>
 
-#ifndef _LIBC
-# define __builtin_expect(expr, val)   (expr)
-#endif
-
 #define RETURN_TYPE char *
 #define AVAILABLE(h, h_l, j, n_l)                       \
   (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l))     \
diff --git a/m4/builtin-expect.m4 b/m4/builtin-expect.m4
new file mode 100644
index 0000000..5f7a323
--- /dev/null
+++ b/m4/builtin-expect.m4
@@ -0,0 +1,34 @@
+dnl Check for __builtin_expect.
+
+dnl Copyright 2016 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl___BUILTIN_EXPECT],
+[
+  AC_CACHE_CHECK([for __builtin_expect],
+    [gl_cv___builtin_expect],
+    [AC_LINK_IFELSE(
+       [AC_LANG_SOURCE([[
+         int
+         main (int argc, char **argv)
+         {
+           argc = __builtin_expect (argc, 100);
+           return argv[argc != 100][0];
+         }]])],
+       [gl_cv___builtin_expect=yes],
+       [gl_cv___builtin_expect=no])])
+  if test "$gl_cv___builtin_expect" = yes; then
+    AC_DEFINE([HAVE___BUILTIN_EXPECT], [1])
+  fi
+  AH_VERBATIM([HAVE___BUILTIN_EXPECT],
+    [/* Define to 1 if the compiler understands __builtin_expect.  */
+#undef HAVE___BUILTIN_EXPECT
+#ifndef HAVE___BUILTIN_EXPECT
+# define __builtin_expect(e, c) (e)
+#endif
+    ])
+])
diff --git a/modules/avltreehash-list b/modules/avltreehash-list
index f4d5699..a7aa75e 100644
--- a/modules/avltreehash-list
+++ b/modules/avltreehash-list
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
 lib/gl_anytreehash_list2.h
 
 Depends-on:
+builtin-expect
 list
 avltree-oset
 stdint
diff --git a/modules/builtin-expect b/modules/builtin-expect
new file mode 100644
index 0000000..c11d5d9
--- /dev/null
+++ b/modules/builtin-expect
@@ -0,0 +1,20 @@
+Description:
+Check for __builtin_expect.
+
+Files:
+m4/builtin-expect.m4
+
+Depends-on:
+
+configure.ac:
+gl___BUILTIN_EXPECT
+
+Makefile.am:
+
+Include:
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/fnmatch b/modules/fnmatch
index ab30236..70563f9 100644
--- a/modules/fnmatch
+++ b/modules/fnmatch
@@ -12,6 +12,7 @@ Depends-on:
 extensions
 snippet/arg-nonnull
 alloca          [test -n "$FNMATCH_H"]
+builtin-expect  [test -n "$FNMATCH_H"]
 flexmember      [test -n "$FNMATCH_H"]
 stdbool         [test -n "$FNMATCH_H"]
 wchar           [test -n "$FNMATCH_H"]
diff --git a/modules/glob b/modules/glob
index f32fe5f..29df7ab 100644
--- a/modules/glob
+++ b/modules/glob
@@ -15,6 +15,7 @@ snippet/arg-nonnull
 snippet/c++defs
 snippet/warn-on-use
 alloca          [test -n "$GLOB_H"]
+builtin-expect  [test -n "$GLOB_H"]
 closedir        [test -n "$GLOB_H"]
 d-type          [test -n "$GLOB_H"]
 dirfd           [test -n "$GLOB_H"]
diff --git a/modules/grantpt b/modules/grantpt
index 38675b6..486bb85 100644
--- a/modules/grantpt
+++ b/modules/grantpt
@@ -9,6 +9,7 @@ m4/grantpt.m4
 Depends-on:
 stdlib
 extensions
+builtin-expect  [test $HAVE_GRANTPT = 0]
 pt_chown        [test $HAVE_GRANTPT = 0]
 waitpid         [test $HAVE_GRANTPT = 0]
 configmake      [test $HAVE_GRANTPT = 0]
diff --git a/modules/memmem-simple b/modules/memmem-simple
index d4ae332..71de887 100644
--- a/modules/memmem-simple
+++ b/modules/memmem-simple
@@ -7,6 +7,7 @@ lib/memmem.c
 m4/memmem.m4
 
 Depends-on:
+builtin-expect
 extensions
 string
 stdint
diff --git a/modules/rbtreehash-list b/modules/rbtreehash-list
index e7369cb..2b4add5 100644
--- a/modules/rbtreehash-list
+++ b/modules/rbtreehash-list
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
 lib/gl_anytreehash_list2.h
 
 Depends-on:
+builtin-expect
 list
 rbtree-oset
 stdint
diff --git a/modules/scandir b/modules/scandir
index 71ef465..8d5e105 100644
--- a/modules/scandir
+++ b/modules/scandir
@@ -6,6 +6,7 @@ lib/scandir.c
 m4/scandir.m4
 
 Depends-on:
+builtin-expect
 closedir
 dirent
 extensions
@@ -31,4 +32,3 @@ LGPL
 
 Maintainer:
 all, glibc
-
diff --git a/modules/strstr-simple b/modules/strstr-simple
index c61afc4..bd52b17 100644
--- a/modules/strstr-simple
+++ b/modules/strstr-simple
@@ -8,6 +8,7 @@ m4/strstr.m4
 
 Depends-on:
 string
+builtin-expect  [test $REPLACE_STRSTR = 1]
 stdbool         [test $REPLACE_STRSTR = 1]
 memchr          [test $REPLACE_STRSTR = 1]
 memcmp          [test $REPLACE_STRSTR = 1]
-- 
2.7.4

Reply via email to