Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang does not implement __assume__ attribute, fails libstdc++ build #71858

Closed
trofi opened this issue Nov 9, 2023 · 6 comments · Fixed by #84934
Closed

clang does not implement __assume__ attribute, fails libstdc++ build #71858

trofi opened this issue Nov 9, 2023 · 6 comments · Fixed by #84934
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" extension:gnu

Comments

@trofi
Copy link
Contributor

trofi commented Nov 9, 2023

gcc implements __assume__ attribute as: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html, quoting the example:

int
foo (int x, int y)
{
  __attribute__((assume(x == 42)));
  __attribute__((assume(++y == 43)));
  return x + y;
}

clang-16 fails to build it as:

$ clang -c a.c
a.c:4:18: error: 'assume' attribute cannot be applied to a statement
  __attribute__((assume(x == 42)));
                 ^                ~
a.c:5:18: error: 'assume' attribute cannot be applied to a statement
  __attribute__((assume(++y == 43)));
                 ^                  ~
2 errors generated.

Recently gcc started using it in libstdc++ https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e39b3e02c27bd7 as

    void
    _M_assume_normalized() const
    {
      unsigned int __ofst = _M_offset;
      __attribute__ ((__assume__ (__ofst < unsigned(_S_word_bit))));
    }

and clang++ now fails to parse <vector> from libstdc++.

Is there a change clang would support this style of __assume__ attribute or at least skipped it in stead of producing build failure?

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 9, 2023
@trofi
Copy link
Contributor Author

trofi commented Nov 9, 2023

Meanwhile filed https://gcc.gnu.org/PR112467 on gcc side to consider using this style of the attribute only for gcc.

@pinskia
Copy link

pinskia commented Nov 9, 2023

Note GCC's assume attribute is the same as C++23 assume standard attribute.
That is: [[assume(x == 0)]]; and __attribute__((assume(x == 0) )); are exactly the same.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" extension:gnu and removed clang Clang issues not falling into any other category labels Nov 9, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 9, 2023

@llvm/issue-subscribers-clang-frontend

Author: Sergei Trofimovich (trofi)

`gcc` implements `__assume__` attribute as: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html, quoting the example:
int
foo (int x, int y)
{
  __attribute__((assume(x == 42)));
  __attribute__((assume(++y == 43)));
  return x + y;
}

clang-16 fails to build it as:

$ clang -c a.c
a.c:4:18: error: 'assume' attribute cannot be applied to a statement
  __attribute__((assume(x == 42)));
                 ^                ~
a.c:5:18: error: 'assume' attribute cannot be applied to a statement
  __attribute__((assume(++y == 43)));
                 ^                  ~
2 errors generated.

Recently gcc started using it in libstdc++ https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e39b3e02c27bd7 as

    void
    _M_assume_normalized() const
    {
      unsigned int __ofst = _M_offset;
      __attribute__ ((__assume__ (__ofst &lt; unsigned(_S_word_bit))));
    }

and clang++ now fails to parse &lt;vector&gt; from libstdc++.

Is there a change clang would support this style of __assume__ attribute or at least skipped it in stead of producing build failure?

@shafik
Copy link
Collaborator

shafik commented Nov 10, 2023

CC @erichkeane @AaronBallman

@erichkeane
Copy link
Collaborator

@AaronBallman is particularly opinionated about attribute assume so he should set our policy here. If it is ok with him, I'd be ok reviewing a statement assume attribute.

@AaronBallman
Copy link
Collaborator

@AaronBallman is particularly opinionated about attribute assume so he should set our policy here. If it is ok with him, I'd be ok reviewing a statement assume attribute.

We had a Discourse thread on this, and my thoughts at the time were: https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609/23 -- my thinking really hasn't changed all that much since then. I think we need LLVM changes before we can effectively implement the attribute and so we should report 0 for __has_cpp_attribute(assume) until we're ready to support the attribute.

@Sirraide Sirraide linked a pull request May 20, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" extension:gnu
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants