bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Gnulib bugs <bug-gnulib@gnu.org>
Subject: fixes for Clang builtins when compiling Emacs on Fedora
Date: Mon, 17 Aug 2020 15:02:41 -0700	[thread overview]
Message-ID: <5e607e6f-ee3a-41bc-67eb-cdc0571d00d0@cs.ucla.edu> (raw)

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

I had a couple of problems with the recent Clang-related fixes on Fedora 31 when 
building Emacs, and worked around them by installing the attached patches, which 
I hope are reasonably self-explanatory.

Fedora 31 uses Clang 9, and if the seeming Clang bugs/incompatibilities are 
fixed in later Clang versions I suppose we can do better there.

[-- Attachment #2: 0001-libc-config-avoid-Clang-s-__diagnose_if__.patch --]
[-- Type: text/x-patch, Size: 2259 bytes --]

From a1433e1b1f692c6ae062305d4c683efafb087b38 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 17 Aug 2020 14:45:38 -0700
Subject: [PATCH 1/2] =?UTF-8?q?libc-config:=20avoid=20Clang=E2=80=99s=20?=
 =?UTF-8?q?=5F=5Fdiagnose=5Fif=5F=5F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/cdefs.h (__warndecl, __warnattr, __errordecl):
For now, do not use __diagnose_if__ here, as this fails
on Fedora 31 with Clang 9.0.1, with diagnostic
"/usr/include/bits/stdio2.h:263:9: error: fgets called with bigger
size than length of destination buffer
[-Werror,-Wuser-defined-warnings]".  I guess Clang 9 warns even
for functions that are not called?
---
 ChangeLog   | 9 +++++++++
 lib/cdefs.h | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index cd00997a9..ba521c265 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2020-08-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+	libc-config: avoid Clang’s __diagnose_if__
+	* lib/cdefs.h (__warndecl, __warnattr, __errordecl):
+	For now, do not use __diagnose_if__ here, as this fails
+	on Fedora 31 with Clang 9.0.1, with diagnostic
+	"/usr/include/bits/stdio2.h:263:9: error: fgets called with bigger
+	size than length of destination buffer
+	[-Werror,-Wuser-defined-warnings]".  I guess Clang 9 warns even
+	for functions that are not called?
+
 	careadlinkat: speedup for GCC 10 with GCC_LINT
 	Inspired by a suggestion by Bruno Haible in:
 	https://lists.gnu.org/r/bug-gnulib/2020-08/msg00155.html
diff --git a/lib/cdefs.h b/lib/cdefs.h
index 74da73404..32a2c40c6 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -148,7 +148,7 @@
 # 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")))
-- 
2.17.1


[-- Attachment #3: 0002-verify-avoid-__built_assume-on-Clang.patch --]
[-- Type: text/x-patch, Size: 2687 bytes --]

From 90599fb7db22298ec062a75f10e1a3b4c5578c55 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 17 Aug 2020 14:47:45 -0700
Subject: [PATCH 2/2] verify: avoid __built_assume on Clang
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/verify.h (assume): Do not use Clang’s __builtin_assume, as
Clang 9 incorrectly diagnoses arguments as having side effects
even when they do not.  I guess Clang 9 considers any function
call as if it had a side effect here.
---
 ChangeLog    |  6 ++++++
 lib/verify.h | 18 +++++++-----------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ba521c265..9ba0cda92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+	verify: avoid __built_assume on Clang
+	* lib/verify.h (assume): Do not use Clang’s __builtin_assume, as
+	Clang 9 incorrectly diagnoses arguments as having side effects
+	even when they do not.  I guess Clang 9 considers any function
+	call as if it had a side effect here.
+
 	libc-config: avoid Clang’s __diagnose_if__
 	* lib/cdefs.h (__warndecl, __warnattr, __errordecl):
 	For now, do not use __diagnose_if__ here, as this fails
diff --git a/lib/verify.h b/lib/verify.h
index 0ba8d5790..d485a0283 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,11 +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.  */
+   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:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17 22:02 Paul Eggert [this message]
2020-08-17 23:37 ` fixes for Clang builtins when compiling Emacs on Fedora Bruno Haible
2020-08-18  1:10   ` Paul Eggert
2020-08-22 10:30     ` Clang __built_assume Bruno Haible
2020-08-22 17:32       ` Paul Eggert
2020-08-22 23:01         ` Clang __builtin_assume Bruno Haible
2020-08-23 13:46 ` clang's __diagnose_if__ and glibc fortify 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=5e607e6f-ee3a-41bc-67eb-cdc0571d00d0@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).