[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fixes for Clang builtins when compiling Emacs on Fedora
From: |
Bruno Haible |
Subject: |
Re: fixes for Clang builtins when compiling Emacs on Fedora |
Date: |
Tue, 18 Aug 2020 01:37:20 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; ) |
Hi Paul,
> 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
Yes, things are a bit more complicated in practice than in theory... I have just
completed the testing on FreeBSD 12, and will test on OpenBSD and macOS next.
> + 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
This is a pity, because these user-defined diagnostics are useful, and
clang does not have __attribute__((__warning__ ...)) that GCC has.
This piece of code in stdio2.h looks like this:
extern char *__REDIRECT (__fgets_chk_warn,
(char *__restrict __s, size_t __size, int __n,
FILE *__restrict __stream), __fgets_chk)
__wur __warnattr ("fgets called with bigger size than length "
"of destination buffer");
__fortify_function __wur char *
fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
{
if (__bos (__s) != (size_t) -1)
{
if (!__builtin_constant_p (__n) || __n <= 0)
return __fgets_chk (__s, __bos (__s), __n, __stream);
if ((size_t) __n > __bos (__s))
return __fgets_chk_warn (__s, __bos (__s), __n, __stream); // <===
line 263
}
return __fgets_alias (__s, __n, __stream);
}
Most likely the cause is that __bos (__s) currently evaluates to 0,
because I did not port the __bos macro, because the corresponding
attribute works differently in clang than in GCC
<https://clang.llvm.org/docs/AttributeReference.html#alloc-size>.
If you have time to finish this corner of clang support, please go
ahead!
> + 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. */
Do you have a test case, that we could check on clang 10 and on future
clang versions?
Bruno
clang's __diagnose_if__ and glibc fortify, Bruno Haible, 2020/08/23