bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH] verify: avoid __builtin_assume
Date: Sat,  5 Sep 2020 17:52:15 -0700	[thread overview]
Message-ID: <20200906005215.1179403-1-eggert@cs.ucla.edu> (raw)

Our latest attempt to use Clang’s __builtin_assume caused a crash
in GNU Emacs that we spent quite some time tracking down as being
caused by the switch to __builtin_assume.  It’s not known whether
the crash is due is a Clang bug or a portability bug in GNU Emacs.
For now, play it safe and avoid __builtin_assume.
* lib/verify.h (_GL_HAS_BUILTIN_ASSUME): Remove.
(assume): Simplify by not trying to use Clang’s __builtin_assume.
---
 ChangeLog    | 11 +++++++++++
 lib/verify.h | 45 ++++++++-------------------------------------
 2 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 454bd762b..053487c72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-09-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+	verify: avoid __builtin_assume
+	Our latest attempt to use Clang’s __builtin_assume caused a crash
+	in GNU Emacs that we spent quite some time tracking down as being
+	caused by the switch to __builtin_assume.  It’s not known whether
+	the crash is due is a Clang bug or a portability bug in GNU Emacs.
+	For now, play it safe and avoid __builtin_assume.
+	* lib/verify.h (_GL_HAS_BUILTIN_ASSUME): Remove.
+	(assume): Simplify by not trying to use Clang’s __builtin_assume.
+
 2020-09-05  Bruno Haible  <bruno@clisp.org>
 
 	Fix several "warning: no previous prototype for function".
diff --git a/lib/verify.h b/lib/verify.h
index ca2a15407..fa1ed717d 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -246,13 +246,6 @@ template <int w>
 
 /* @assert.h omit start@  */
 
-#if defined __has_builtin
-/* <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions> */
-# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume)
-#else
-# define _GL_HAS_BUILTIN_ASSUME 0
-#endif
-
 #if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
 # define _GL_HAS_BUILTIN_TRAP 1
 #elif defined __has_builtin
@@ -312,36 +305,14 @@ template <int w>
 
    Although assuming R can help a compiler generate better code or
    diagnostics, performance can suffer if R uses hard-to-optimize
-   features such as function calls not inlined by the compiler.  */
-
-/* Use __builtin_assume in preference to __builtin_unreachable, because
-   in clang versions 8.0.x and older, the definition based on
-   __builtin_assume has an effect on optimizations, whereas the definition
-   based on __builtin_unreachable does not.  (GCC so far has only
-   __builtin_unreachable.)  */
-#if _GL_HAS_BUILTIN_ASSUME
-/* Use __builtin_constant_p to help clang's data-flow analysis for the case
-   assume (0).
-   Use a temporary variable, to avoid a clang warning
-   "the argument to '__builtin_assume' has side effects that will be discarded"
-   if R contains invocations of functions not marked as 'const'.
-   The type of the temporary variable can't be __typeof__ (R), because that
-   does not work on bit field expressions.  Use '_Bool' or 'bool' as type
-   instead.  */
-# if defined __cplusplus
-#  define assume(R) \
-     (__builtin_constant_p (R) && !(R) \
-      ? (void) __builtin_unreachable () \
-      : (void) ({ bool _gl_verify_temp = (R); \
-                  __builtin_assume (_gl_verify_temp); }))
-# else
-#  define assume(R) \
-     (__builtin_constant_p (R) && !(R) \
-      ? (void) __builtin_unreachable () \
-      : (void) ({ _Bool _gl_verify_temp = (R); \
-                  __builtin_assume (_gl_verify_temp); }))
-# endif
-#elif _GL_HAS_BUILTIN_UNREACHABLE
+   features such as function calls not inlined by the compiler.
+
+   Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
+   as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
+   <https://bugs.gnu.org/43152#71>.  It's not known whether this breakage
+   is a Clang bug or an Emacs bug; play it safe for now.  */
+
+#if _GL_HAS_BUILTIN_UNREACHABLE
 # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER
 # define assume(R) __assume (R)
-- 
2.25.4



             reply	other threads:[~2020-09-06  0:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06  0:52 Paul Eggert [this message]
2020-09-06  8:46 ` [PATCH] verify: avoid __builtin_assume Bruno Haible
2020-09-20 14:57   ` Bruno Haible
2020-09-20 17:23     ` Jim Meyering
2020-09-20 19:07       ` gnulib-ci project Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200906005215.1179403-1-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).