Comments (5)
Thank you very much for this anazing project.
Thank you for your kind words!
How should I use these tools to compile a real project?
Sorry, but I won't be able to help. I've not worked with Clang for a few years now and I'd need to spend some time trying this myself. Sadly I don't have the spare cycles to try that :(
from clang-tutor.
Thank you very much for this anazing project.
Thank you for your kind words!
How should I use these tools to compile a real project?
Sorry, but I won't be able to help. I've not worked with Clang for a few years now and I'd need to spend some time trying this myself. Sadly I don't have the spare cycles to try that :(
Thank you very much for your reply. I am currently studying llvm/clang
, and I hope to keep the normal compilation process and use llvm/clang
for code analysis during the compilation process. I've successfully used llvm pass
to process its IR code during the compilation process without destroying the compilation process(and ofcourse get output file). However, sometimes my analysis needs to use information in the source code (not information from LLVM-IR). I'm trying to useclang plugins
to solve it. However I can only get intermediate analysis results, but I can't get output files normally(I've already tried adding the -o option and consulted a lot of information). This would interrupt the compilation process of some projects, causing me to only get incomplete analysis results from a portion of the sources files.
To meet my needs, a possible solution might be to use tools like rizsotto/Bear
to compile the project and obtain the compile_commands.json
compilation process file. Then, the compilation information in the file would be manually combined, and clang
would be modified to parameters similar to clang -cc1 -load /path/to/libCodeStyleChecker.so -plugin CSC
to obtain the entire compilation analysis result. (However, I don't particularly like this workflow)
I am not sure whether the clang plugin
provides capabilities similar to llvm pass
to analyze or modify code during the compilation process. I will continue to try something new. If I have a corresponding solution, I will reply here and pull the specific examples to this project :)
Finally, I would like to express my gratitude to you once again!
from clang-tutor.
I am not sure whether the clang plugin provides capabilities similar to llvm pass to analyze or modify code during the compilation process
This makes me realise ... Running a plugin in Clang means running a specific "frontend action". Clang allows only one "action" at a time and it sounds like you are trying to run two actions - sadly that's not supported.
Hope this helps :)
from clang-tutor.
Clang allows only one "action" at a time
Sorry I don't quite understand what you mean.
After our last communication, I made some more attempts, and I believe I have achieved my requirements. I can now compile as follows:
$ clang -fplugin=../lib/libCodeStyleChecker.so -o test.o -c ../../test/LACFloat.cpp
../../test/LACFloat.cpp:7:16: warning: Type and variable names should start with upper-case letter
void foo(float some_arg);
^~~~~~~~~
Some_arg
../../test/LACFloat.cpp:7:20: warning: `_` in names is not allowed
void foo(float some_arg);
~~~~^~~~~
somearg
2 warnings generated.
$ nm test.o
0000000000000000 r .LCPI0_0
0000000000000000 T _Z3barv
U _Z3foof
It seems that I have successfully compiled this file and successfully used the CodeStyleChecker tool to give me hints during the compilation process.
Furthermore, I tried to compile a real project, ffmpeg
, in this way, and successfully got an executable file.
$ ./configure --prefix=../build --cc="clang -fplugin=/home/waji/Workspace/Testspace/clang-ast/clang-tutor/build/lib/libCodeStyleChecker.so" --cxx="clang -fplugin=/home/waji/Workspace/Testspace/clang-ast/clang-tutor/build/lib/libCodeStyleChecker.so" --disable-asm
$ make
$ ./ffmpeg -version
...
libswscale/output.c:2175:52: warning: Type and variable names should start with upper-case letter
yuv2anyX_fn *yuv2anyX)
^~~~~~~~~
Yuv2anyX
libswscale/output.c:2177:24: warning: Type and variable names should start with upper-case letter
enum AVPixelFormat dstFormat = c->dstFormat;
^~~~~~~~~
DstFormat
libswscale/output.c:2178:31: warning: Type and variable names should start with upper-case letter
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
^~~~
Desc
3414 warnings generated.
AR libswscale/libswscale.a
LD ffmpeg_g
LD ffprobe_g
LD ffserver_g
CP ffserver
STRIP ffserver
CP ffprobe
CP ffmpeg
STRIP ffprobe
STRIP ffmpeg
$ ./ffmpeg -version
ffmpeg version n3.2.1 Copyright (c) 2000-2016 the FFmpeg developers
built with clang version 12.0.1 (https://gitee.com/mirrors/LLVM.git fed41342a82f5a3a9201819a82bf7a48313e296b)
configuration: --prefix=../build --cc='clang -fplugin=/home/waji/Workspace/Testspace/clang-ast/clang-tutor/build/lib/libCodeStyleChecker.so' --cxx='clang -fplugin=/home/waji/Workspace/Testspace/clang-ast/clang-tutor/build/lib/libCodeStyleChecker.so' --disable-asm
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
It can be seen that I have successfully compiled ffmpeg (although the compilation process has significantly slowed down), and obtained a binary program that can be executed normally. This meets my needs:
I hope to keep the normal compilation process and use llvm/clang for code analysis during the compilation process.
My modification is very simple. On the official website of the Clang Plugin, I found the answer. You can automatically add a plugin in the public PluginASTAction
by overriding the getActionType
function:
// Automatically run the plugin after the main AST action
PluginASTAction::ActionType getActionType() override {
return AddAfterMainAction;
}
PR in #34
from clang-tutor.
I found something new:
$ clang -cc1 -help | grep "plugin"
-add-plugin <name> Use the named plugin action in addition to the default action
-fpass-plugin=<dsopath> Load pass plugin from a dynamic shared object file (only with new pass manager).
-load <dsopath> Load the named plugin (dynamic shared object)
-plugin-arg-<name> <arg>
Pass <arg> to plugin <name>
-plugin <name> Use the named plugin action instead of the default action (use "help" to list available options)
When we passing plugin with -plugin
, clang will replace the default compile action to our specify action. But we can use plugin with -add-plugin
, which would keep the default action and add the specify action following the getActionType()
return.
So, I can make CodeStyleChecker
during my compile process, like following (without change any codes in CodeStyleChecker.cpp
):
clang -Xclang -load -Xclang lib/libCodeStyleChecker.so -Xclang -add-plugin -Xclang CSC -o 1.o -c ../test/CodeStyleCheckerFunction.cpp
I'm now study how to write test suits with lit
(and add some docs)
from clang-tutor.
Related Issues (17)
- Example for instrumenting source code HOT 1
- Windows build fails to work with clang++ HOT 7
- JIT related? HOT 1
- Obfuscator output is weird for the input with both + and - operations HOT 2
- Fix building against LLVM/Clang configured with BUILD_SHARED_LIBS=ON HOT 1
- Visual Studio compiler lib import problem HOT 4
- What's the difference between TraverseForStmt and VisitForStmt? HOT 1
- LLVM 13 HOT 4
- [IDEA] const-qualify tool HOT 2
- [IDEA] Convert types to correct ones: `for(int i=0; i<vec.size(); i++)` => `for(size_t i=0; i<vec.size(); i++)` HOT 6
- Questions about rationale of ASTMatcher and RecursiveASTVisitor? HOT 1
- Error happen when include STL header
- No CMAKE_CXX_COMPILER could be found. HOT 3
- Run on Windows 11 Native HOT 1
- Compiles against clang 16/17/18
- [ERROR]$Clang_DIR/bin/clang -cc1 -load ./libHelloWorld.{so|dylib} -plugin hello-world $CLANG_TUTOR_DIR/test/HelloWorld-basic.cpp HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clang-tutor.