Bug 112467 - [14 Regression] libstdc++ fails to build on clang: bits/stl_bvector.h:189:23: error: '__assume__' attribute cannot be applied to a statement
Summary: [14 Regression] libstdc++ fails to build on clang: bits/stl_bvector.h:189:23:...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-09 19:38 UTC by Sergei Trofimovich
Modified: 2024-02-09 08:46 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-11-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2023-11-09 19:38:52 UTC
Build failure is probably introduced by r14-5260-ge39b3e02c27bd7 and fails on clang-16 as:

    // $ cat a.cc
    #include <vector>

$ clang++ -c a.cc
In file included from a.cc:1:
In file included from /<<NIX>>/gcc-14.0.0/include/c++/14.0.0/vector:67:
/<<NIX>>/gcc-14.0.0/include/c++/14.0.0/bits/stl_bvector.h:189:23: error: '__assume__' attribute cannot be applied to a statement
      __attribute__ ((__assume__ (__ofst < unsigned(_S_word_bit))));
                      ^                                            ~
1 error generated.

I think it happens because `clang` implements different `assume` attribute compared to `gcc`: https://clang.llvm.org/docs/AttributeReference.html#assume
Comment 1 Andrew Pinski 2023-11-09 19:49:01 UTC
GCC/GNUC's assume is the same as the way C++23 attribute is defined ...

Looks like clang decided to implement an attribute assume which is totally different ...
Comment 2 Sergei Trofimovich 2023-11-09 19:49:26 UTC
Filed a feature request on `clang` side to consider implementing it: https://github.com/llvm/llvm-project/issues/71858

Meanwhile would it be reasonable to enable the attribute only for `gcc`?
Comment 3 Andrew Pinski 2023-11-09 19:50:21 UTC
(In reply to Sergei Trofimovich from comment #2)
> Meanwhile would it be reasonable to enable the attribute only for `gcc`?

Or rather for !__CLANG__  :).
Comment 4 Jonathan Wakely 2023-11-09 21:15:24 UTC
No, for __has_attribute(__assume__)
Comment 5 Jonathan Wakely 2023-11-09 21:15:52 UTC
Oh, but that's presumably true for clang, just not in this context. Ugh.
Comment 6 Sam James 2023-11-10 20:58:55 UTC
I hit the same when building Firefox with Clang which figures.
Comment 7 Jonathan Wakely 2023-11-10 21:05:23 UTC
This seems to work:

--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -185,8 +185,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     void
     _M_assume_normalized() const
     {
+#if __has_attribute(__assume__) && !defined(__clang__)
       unsigned int __ofst = _M_offset;
       __attribute__ ((__assume__ (__ofst < unsigned(_S_word_bit))));
+#endif
     }
 
     _GLIBCXX20_CONSTEXPR
Comment 8 GCC Commits 2023-11-11 00:58:15 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:807f47497f17ed50be91f0f879308cb6fa063966

commit r14-5350-g807f47497f17ed50be91f0f879308cb6fa063966
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Nov 10 21:06:15 2023 +0000

    libstdc++: Do not use assume attribute for Clang [PR112467]
    
    Clang has an 'assume' attribute, but it's a function attribute not a
    statement attribute. The recently-added use of the statement form causes
    an error with Clang.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/112467
            * include/bits/stl_bvector.h (_M_assume_normalized): Do not use
            statement form of assume attribute for Clang.
Comment 9 Jonathan Wakely 2023-11-11 01:01:25 UTC
done
Comment 10 GCC Commits 2024-02-09 08:46:55 UTC
The releases/gcc-13 branch has been updated by Torbjorn Svensson <azoff@gcc.gnu.org>:

https://gcc.gnu.org/g:adef1e0ebeb5055ed4e8776fd3f73c9d84821eaa

commit r13-8310-gadef1e0ebeb5055ed4e8776fd3f73c9d84821eaa
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Nov 10 21:06:15 2023 +0000

    libstdc++: Do not use assume attribute for Clang [PR112467]
    
    Clang has an 'assume' attribute, but it's a function attribute not a
    statement attribute. The recently-added use of the statement form causes
    an error with Clang.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/112467
            * include/bits/stl_bvector.h (_M_assume_normalized): Do not use
            statement form of assume attribute for Clang.
    
    (cherry picked from commit 807f47497f17ed50be91f0f879308cb6fa063966)