all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: __builtin_assume warnings
Date: Mon, 17 Aug 2020 15:11:34 -0700	[thread overview]
Message-ID: <1da4c4ff-f057-f4ac-c3ec-3232bc0a4477@cs.ucla.edu> (raw)
In-Reply-To: <F418C477-1EB8-4356-94D4-C22AD7F94E57@acm.org>

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On 8/17/20 7:05 AM, Mattias Engdegård wrote:
>   Looks like Clang does not yet look inside inline functions for -Wassume.

I guess that for that diagnostic, Clang assumes that every function call has a 
side effect, which is pretty silly. I worked around the bug (and by an another 
bogus-warning bug I ran into on Fedora 31's Clang 9.0.1) by installing the attached.

[-- Attachment #2: 0001-Update-from-Gnulib.patch --]
[-- Type: text/x-patch, Size: 2707 bytes --]

From 352b7dede0b3a28024a41a3da1c340859b110665 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 17 Aug 2020 15:05:05 -0700
Subject: [PATCH] Update from Gnulib
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This incorporates:
2020-08-17 verify: avoid __built_assume on Clang
2020-08-17 libc-config: avoid Clang’s __diagnose_if__
* lib/cdefs.h, lib/verify.h: Copy from Gnulib.
---
 lib/cdefs.h  |  2 +-
 lib/verify.h | 18 +++++++-----------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/cdefs.h b/lib/cdefs.h
index 0cc27806a1..b1870fd0a9 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -148,7 +148,7 @@ #define __bos0(ptr) __builtin_object_size (ptr, 0)
 # define __warnattr(msg) __attribute__((__warning__ (msg)))
 # define __errordecl(name, msg) \
   extern void name (void) __attribute__((__error__ (msg)))
-#elif __glibc_clang_has_attribute (__diagnose_if__)
+#elif __glibc_clang_has_attribute (__diagnose_if__) && 0 /* fails on Fedora 31 with Clang 9.  */
 # define __warndecl(name, msg) \
   extern void name (void) __attribute__((__diagnose_if__ (1, msg, "warning")))
 # define __warnattr(msg) __attribute__((__diagnose_if__ (1, msg, "warning")))
diff --git a/lib/verify.h b/lib/verify.h
index 0ba8d57907..d485a0283a 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -246,13 +246,6 @@ #define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
 
 /* @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,11 +305,14 @@ #define verify_expr(R, E) \
 
    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.  */
+   features such as function calls not inlined by the compiler.
+
+   Avoid Clang’s __builtin_assume, as clang 9.0.1 -Wassume can
+   generate a bogus diagnostic "the argument to '__builtin_assume' has
+   side effects that will be discarded" even when the argument has no
+   side effects.  */
 
-#if _GL_HAS_BUILTIN_ASSUME
-# define assume(R) __builtin_assume (R)
-#elif _GL_HAS_BUILTIN_UNREACHABLE
+#if _GL_HAS_BUILTIN_UNREACHABLE
 # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER
 # define assume(R) __assume (R)
-- 
2.17.1


  reply	other threads:[~2020-08-17 22:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12  9:38 __builtin_assume warnings Mattias Engdegård
2020-08-15  2:32 ` Paul Eggert
2020-08-16  8:23   ` Mattias Engdegård
2020-08-17 14:05     ` Mattias Engdegård
2020-08-17 22:11       ` Paul Eggert [this message]
2020-08-18  7:11         ` Mattias Engdegård
2020-08-18 22:53           ` Paul Eggert
2020-08-19  8:01             ` Mattias Engdegård

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

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

  git send-email \
    --in-reply-to=1da4c4ff-f057-f4ac-c3ec-3232bc0a4477@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.