[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: __builtin_add_overflow on clang

From: Paul Eggert
Subject: Re: __builtin_add_overflow on clang
Date: Sun, 25 Aug 2019 19:40:08 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

Mattias EngdegÄrd wrote:
On macOS (and *BSD, probably), compiler-rt is linked by default so the problem 
never arises there. Much as I dislike them in general, perhaps a configure test 
would be appropriate?

I've been avoiding configure-time tests for intprops.h, since we haven't needed them yet and intprops.h is occasionally used outside Gnulib. And strictly speaking we don't need the tests here, as the fallback code works correctly for Clang (albeit most likely not as efficiently).

The reason I patched Gnulib in 2017 to work around the Clang bug:


was in response to a private bug report for GNU 'sed' builds from Nelson H.F. Beebe, who reported finding the Clang bug on these platforms:

    alpine3           dragonflybsd47    mageia6           salix142
    alpine343         fedorarh          mint18            slackware142
    alpine35          fedorarh          mint181           slackware142x
    beta              gentoo            openbsd60         solus12
    clearos7          grousecreek       opensusetw        ubuntu1610
    dragonflybsd46    kali2             pclinuxos         ubunturr
    dragonflybsd461   mageia6           pclinuxosb        void64

These failures occurred with ordinary integer types, as sed doesn't use 128-bit types.

Beebe also wrote:

I fear that others might hit the problem, and because Mac OS X
and recent FreeBSD have switched to clang as the default C compiler,
the same problem might start showing up on those platforms.

Given the prevalence of this Clang bug, and the iffiness of whether the bug might occur on macOS or FreeBSD, I was cautious and stuck with the fallback code for Clang. However, now that you mention it this problem seems limited to multiplication and it's easy to change intprops.h to use Clang's __builtin_add_overflow and __builtin_sub_overflow even if its __builtin_mul_overflow is buggy. So I installed the attached patch into Gnulib to do that.

If we definitely know that this bug cannot occur on FreeBSD and/or macOS, I suppose we could add further tests on the appropriate preprocessor macros. But that would require further investigation as to what packages are available in these platforms and whether the relevant clang runtimes can be installed separately.

Attachment: 0001-intprops.h-verify.h-port-better-to-clang.txt
Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]