This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Move formatDereference to FixitHintUtils
ClosedPublic

Authored by mikecrowe on May 15 2023, 12:28 PM.

Details

Summary

I'd like to use RedundantStringCStrCheck's formatDereference function
from the up-coming modernize-use-std-print check. Let's move it to
FixItHintUtils so that the implementation can be shared.

Diff Detail

Event Timeline

mikecrowe created this revision.May 15 2023, 12:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2023, 12:28 PM
Herald added a subscriber: xazax.hun. · View Herald Transcript
mikecrowe requested review of this revision.May 15 2023, 12:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2023, 12:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
PiotrZSL accepted this revision.May 23 2023, 11:03 AM

LGTM, code compiles locally, restarted CI job (maybe will pass).
Add [NFC] to change title before committing as this changes does not impact functionality.

clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
230
NOTE: make this internal function static so it would have internal linkage.
This revision is now accepted and ready to land.May 23 2023, 11:03 AM
mikecrowe marked an inline comment as done.May 23 2023, 11:33 AM

Thanks for the review. New version with the static added coming shortly.

Make needParensAfterUnaryOperator static

PiotrZSL accepted this revision.May 23 2023, 11:44 AM

Rebase, no changes.

I will push this change, no point to keep it open.

This revision was automatically updated to reflect the committed changes.
PiotrZSL reopened this revision.Jun 11 2023, 11:28 PM

Looks like there is missing dependency in CMake:
https://lab.llvm.org/buildbot/#/builders/57/builds/27531

FAILED: lib/libclangTidyUtils.so.17git 
: && /home/buildbots/clang.15.0.4/bin/clang++ --gcc-toolchain=/usr -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete -Wl,--color-diagnostics   -Wl,--gc-sections -shared -Wl,-soname,libclangTidyUtils.so.17git -o lib/libclangTidyUtils.so.17git tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/Aliasing.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/ASTUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/DeclRefExprUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/ExceptionAnalyzer.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/ExceptionSpecAnalyzer.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/ExprSequence.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FileExtensionsUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FixItHintUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/HeaderGuard.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/IncludeInserter.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/IncludeSorter.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/LexerUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/NamespaceAliaser.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/OptionsUtils.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/RenamerClangTidyCheck.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/TransformerClangTidyCheck.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/TypeTraits.cpp.o tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/UsingInserter.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib:/home/buildbots/docker-RHEL84-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/lib:"  lib/libclangTidy.so.17git  lib/libclangTransformer.so.17git  lib/libclangSema.so.17git  lib/libclangASTMatchers.so.17git  lib/libclangAST.so.17git  lib/libLLVMFrontendOpenMP.so.17git  lib/libclangLex.so.17git  lib/libclangBasic.so.17git  lib/libLLVMSupport.so.17git  -Wl,-rpath-link,/home/buildbots/docker-RHEL84-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/lib && :
ld.lld: error: undefined symbol: clang::tooling::fixit::internal::getText(clang::CharSourceRange, clang::ASTContext const&)
>>> referenced by FixItHintUtils.cpp
>>>               tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FixItHintUtils.cpp.o:(clang::tidy::utils::fixit::formatDereference[abi:cxx11](clang::Expr const&, clang::ASTContext const&))
>>> referenced by FixItHintUtils.cpp
>>>               tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FixItHintUtils.cpp.o:(clang::tidy::utils::fixit::formatDereference[abi:cxx11](clang::Expr const&, clang::ASTContext const&))
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
This revision is now accepted and ready to land.Jun 11 2023, 11:28 PM
mikecrowe updated this revision to Diff 530662.Jun 12 2023, 2:04 PM

Add clangTooling to LINK_LIBS for tooling::fixit::getText for clangTidyUtils to fix failure to build with BUILD_SHARED_LIBS=ON:

ld.lld: error: undefined symbol: clang::tooling::fixit::internal::getText(clang::CharSourceRange, clang::ASTContext const&)
>>> referenced by FixItHintUtils.cpp
>>>               tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FixItHintUtils.cpp.o:(clang::tidy::utils::fixit::formatDereference[abi:cxx11](clang::Expr const&, clang::ASTContext const&))
>>> referenced by FixItHintUtils.cpp
>>>               tools/clang/tools/extra/clang-tidy/utils/CMakeFiles/obj.clangTidyUtils.dir/FixItHintUtils.cpp.o:(clang::tidy::utils::fixit::formatDereference[abi:cxx11](clang::Expr const&, clang::ASTContext const&))

I've no idea whether this is a sensible solution, but it does seem to work in my testing.

I think it should be under clang_target_link_libraries

mikecrowe updated this revision to Diff 530943.Jun 13 2023, 9:37 AM

Move clangTooling to clang_target_link_libraries

This revision was automatically updated to reflect the committed changes.