mgehre / xunused Goto Github PK
View Code? Open in Web Editor NEWxunused is a tool to find unused C/C++ functions and methods across source files in the whole project.
License: Apache License 2.0
xunused is a tool to find unused C/C++ functions and methods across source files in the whole project.
License: Apache License 2.0
I tried to use this tool on a linux tool, but it fails to parse my compilation database.
Thanks for making this tool, it's been really helpful finding some dead code for us!
We have a lot of __attribute__((weak))
functions for test tracing and whatnot, is it possible to recognize these cases? I'm suspecting not since weak overrides happen during linkage but I'm not familiar enough with Clang's tooling to understand if it can figure that out.
Example that xunused thought was unused:
// main.c
void __attribute__((weak)) foo(void) {
}
int main(void) {
foo();
}
// test_wrap.c
// This one was found to be "unused"
void foo(void) {
// Does actual stuff
}
Matthias, in the README.md
, I would add cd build
before cmake ..
Clang is updated quite a lot.
It would be nice to support latest version (10).
Also, I don't think it's worth to have several versions if it's hard to maintain, so support of version 9 (and 8) is under question.
I downloaded the clang-8.0.0 binary distribution for Mac OS X and attempted to build, but it seems to complain about missing typeinfo in llvm:
/Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/xunused.dir/link.txt --verbose=1
/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/bin/clang++ -std=c++17 -isysroot /Applications/Xcode_10.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/xunused.dir/main.cpp.o -o xunused -L/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib -Wl,-rpath,/Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib -lclangIndex -lclangTooling -lclangFrontend -lclangDriver -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangASTMatchers -lclangAST -lclangEdit -lclangLex -lclangBasic /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86AsmParser.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMSupport.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMOption.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMProfileData.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Desc.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86AsmPrinter.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Utils.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMCDisassembler.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMObject.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMCParser.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMMC.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDebugInfoCodeView.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDebugInfoMSF.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMBitReader.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMX86Info.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMCore.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMBinaryFormat.a /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMSupport.a -lz -lcurses -lm /Users/robb/clang+llvm-8.0.0-x86_64-apple-darwin/lib/libLLVMDemangle.a
Undefined symbols for architecture x86_64:
"typeinfo for llvm::ErrorInfoBase", referenced from:
typeinfo for llvm::ErrorInfo<llvm::ErrorList, llvm::ErrorInfoBase> in main.cpp.o
"typeinfo for clang::ASTConsumer", referenced from:
typeinfo for XUnusedASTConsumer in main.cpp.o
"typeinfo for clang::ast_matchers::MatchFinder::MatchCallback", referenced from:
typeinfo for FunctionDeclMatchHandler in main.cpp.o
"typeinfo for clang::ASTFrontendAction", referenced from:
typeinfo for XUnusedFrontendAction in main.cpp.o
"typeinfo for clang::tooling::FrontendActionFactory", referenced from:
typeinfo for XUnusedFrontendActionFactory in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
gnumake[2]: *** [xunused] Error 1
gnumake[1]: *** [CMakeFiles/xunused.dir/all] Error 2
gnumake: *** [all] Error 2
robb@Robs-MacBook-Pro:~/SkunkWorks/xunused/build (master)$
Do I need to build llvm from scratch with rtti turned on?
~/workspace/waa_dev/xunused \ue0b0 \ue0a0 * \ue0b0 build \ue0b0 make 765ms \ue0b3 Tue Oct 12 06:27:00 2021
Scanning dependencies of target xunused
[ 50%] Building CXX object CMakeFiles/xunused.dir/main.cpp.o
[100%] Linking CXX executable xunused
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI28XUnusedFrontendActionFactory[_ZTI28XUnusedFrontendActionFactory]+0x10): undefined reference to typeinfo for clang::tooling::FrontendActionFactory' /bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI21XUnusedFrontendAction[_ZTI21XUnusedFrontendAction]+0x10): undefined reference to
typeinfo for clang::ASTFrontendAction'
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI18XUnusedASTConsumer[_ZTI18XUnusedASTConsumer]+0x10): undefined reference to typeinfo for clang::ASTConsumer' /bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTI24FunctionDeclMatchHandler[_ZTI24FunctionDeclMatchHandler]+0x10): undefined reference to
typeinfo for clang::ast_matchers::MatchFinder::MatchCallback'
/bin/ld: CMakeFiles/xunused.dir/main.cpp.o:(.data.rel.ro._ZTIN4llvm9ErrorInfoINS_9ErrorListENS_13ErrorInfoBaseEEE[_ZTIN4llvm9ErrorInfoINS_9ErrorListENS_13ErrorInfoBaseEEE]+0x10): undefined reference to `typeinfo for llvm::ErrorInfoBase'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/xunused.dir/build.make:108: xunused] Error 1
make[1]: *** [CMakeFiles/Makefile2:79: CMakeFiles/xunused.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
[ 50%] Building CXX object CMakeFiles/xunused.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -I/opt/llvm18/include -I/opt/include -I /opt/openssl-3.2.1/include -O3 -march=native -funroll-loops -finline-functions -mtune=native -Wno-everything -O3 -DNDEBUG -std=gnu++17 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -mmacosx-version-min=14.4 -fcolor-diagnostics -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -MD -MT CMakeFiles/xunused.dir/main.cpp.o -MF CMakeFiles/xunused.dir/main.cpp.o.d -o CMakeFiles/xunused.dir/main.cpp.o -c /xunused/main.cpp
/xunused/main.cpp:178:37: error: no member named 'isPure' in 'clang::CXXMethodDecl'
if (MD->isVirtual() && !MD->isPure() && MD->size_overridden_methods())
~~ ^
1 error generated.
make[2]: *** [CMakeFiles/xunused.dir/build.make:76: CMakeFiles/xunused.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/xunused'
make[1]: *** [CMakeFiles/Makefile2:218: CMakeFiles/xunused.dir/all] Error 2
make[1]: Leaving directory '/xunused'
make: *** [Makefile:136: all] Error 2
Sometimes function or method is used just once and could be embedded into caller.
First attempt to use xunused, following the instructions in READ.me
, fails:
$ bear --output /io/h.json -- ninja
$ /Gext/xunused/build/xunused /io/h.json
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/io/h.json"
No compilation database found in /io or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.