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-tidy] llvmlibc-inline-function-decl erroneously reports on lambda functions #62147

Closed
jhuber6 opened this issue Apr 14, 2023 · 2 comments
Assignees

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Apr 14, 2023

The llvmlibc-inline-function-decl currently erroneously reports when defining a lambda function. The reason LLVM's libc reports on these variables so that we can ensure functions in headers line up when compiled differently for different TUs. However, the functions emitted from lambda values will have internal linkage, so they will be unique to each TU they are implemented in. Here is a reproducer.

namespace __llvm_libc {

void foo(void (*fn)(void));

void bar() {
  foo([]() {});
}

} // namespace __llvm_libc
$ clang-tidy test.h --checks=-'*,llvmlibc*'               
8 warnings generated.
test.h:6:7: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
  foo([]() {});
      ^
test.h:6:7: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
test.h:6:7: warning: '~(lambda at /home/jhuber/Documents/llvm/llvm-project/build/test.h:6:7)' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
test.h:6:10: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
  foo([]() {});
         ^
Suppressed 4 warnings (4 with check filters).
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 14, 2023

@llvm/issue-subscribers-libc

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 16, 2023

@llvm/issue-subscribers-clang-tidy

@carlosgalvezp carlosgalvezp changed the title [libc] llvmlibc-inline-function-decl erroneously reports on lambda functions [clang-tidy] llvmlibc-inline-function-decl erroneously reports on lambda functions Apr 16, 2023
flemairen6 pushed a commit to Xilinx/llvm-project that referenced this issue May 10, 2023
…mbdas

The `llvmlibc-inline-function-decl` check is intended to be used to
allow declarations in the `libc` project's header to be changed per-TU.
However, it is impossible to place this macro in front of a lambda so
this is not helpful. Additionally, lambdas are always going to have
internal linkage so they will not differ accross TUs.

Fixes llvm#62147

Reviewed By: lntue, PiotrZSL

Differential Revision: https://reviews.llvm.org/D148444
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants