This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas
ClosedPublic

Authored by jhuber6 on Apr 15 2023, 4:34 PM.

Details

Summary

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 https://github.com/llvm/llvm-project/issues/62147

Diff Detail

Event Timeline

jhuber6 created this revision.Apr 15 2023, 4:34 PM
jhuber6 requested review of this revision.Apr 15 2023, 4:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 4:34 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
lntue accepted this revision.Apr 15 2023, 4:36 PM
This revision is now accepted and ready to land.Apr 15 2023, 4:36 PM
PiotrZSL added a comment.EditedApr 15 2023, 10:55 PM

Missing test

clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
43

auto -> const auto

This comment was removed by PiotrZSL.
PiotrZSL requested changes to this revision.Apr 15 2023, 10:57 PM

Add test

This revision now requires changes to proceed.Apr 15 2023, 10:57 PM
carlosgalvezp added inline comments.Apr 16 2023, 5:47 AM
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
43

Since there are 2 lines under this if, please add braces for better readability.

clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
64–67

Not needed, simply write a plain comment explaining why the check should not warn here.

jhuber6 updated this revision to Diff 513997.Apr 16 2023, 5:53 AM

Address nit

clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
64–67

Since I've already written it I think we should be able to keep it. If really you don't like the extra check lines I can remove them.

PiotrZSL accepted this revision.Apr 16 2023, 6:09 AM

From functional point of view it's looking good.

clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
42
NOTE: This comment refers also to inline exclusion in line 33. I don't think is needed, or you can extract line 33 and 43 into separate function like isExternalyVisibleDeclaration, and to be honest for check that there are other ways, some checks already do that, because simply then you can ask your self, what about coonstexpr functions, what about static functions, functions in anonymous namespace In theory they also may be catch here. Even that inline keyword could be redundant.
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
66
NOTE: If this warning were printed then we got other issue in this check. Implicit functions are checked, would be good to exclude them: functionDecl(unless(isImplicit())).
This revision is now accepted and ready to land.Apr 16 2023, 6:09 AM

Fix Linux build before committing & resolve all comments.

Fix Linux build before committing & resolve all comments.

The log says that it failed because of the CMake version. I don't think I can fix that.

clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
66

That was printed without this patch. Are you saying we should have a separate check for these types of functions?

PiotrZSL added inline comments.Apr 16 2023, 6:30 AM
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
66

I'm just telling that this shouldn't be printed in first place because they are implicit, so there is no place to add macro.
For me this is another bug in this check that should be addressed (probably in separate patch).

Rebase code, this will fix a build.

jhuber6 updated this revision to Diff 514001.Apr 16 2023, 6:37 AM

Rebasing on main

Additionally, lambdas are always going to have internal linkage so they will not differ accross TUs.

This isn't true - if a lambda appears in a header in any way, it probably has linkage the same as an inline function, not internal.

(eg: a lambda inside an inline function has linkage so it gets deduplicated with other copies from different inclusions of a header)