-
-
Save RReverser/633123e0c102a231e19080b25e563601 to your computer and use it in GitHub Desktop.
Revisions
-
RReverser revised this gist
Nov 2, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
RReverser revised this gist
Oct 31, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class PrintGlobalsVisitor : public clang::RecursiveASTVisitor<PrintGlobalsVisito bool VisitVarDecl(clang::VarDecl *D) { const clang::SourceManager &SM = Context->getSourceManager(); if (D->hasGlobalStorage() && !D->getType().isConstQualified()) { clang::FullSourceLoc loc = Context->getFullLoc(D->getBeginLoc()); if (!SM.isInSystemHeader(loc)) { clang::DiagnosticsEngine &D = *Diagnostics; unsigned int id = D.getCustomDiagID(clang::DiagnosticsEngine::Warning, "global variable"); -
shardest revised this gist
Apr 23, 2020 . 2 changed files with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,8 +49,8 @@ class PrintGlobalsConsumer : public clang::ASTConsumer { class PrintGlobalsAction : public clang::PluginASTAction { protected: std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef) { return std::unique_ptr<clang::ASTConsumer>(new PrintGlobalsConsumer(&CI.getASTContext(), &CI.getDiagnostics())); } bool ParseArgs(const clang::CompilerInstance &CI, @@ -63,4 +63,4 @@ class PrintGlobalsAction : public clang::PluginASTAction { } static clang::FrontendPluginRegistry::Add<PrintGlobalsAction> X("warn-globals", "generate warnings for non-const global variables"); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ warnglobals.so: ClangWarnGlobals.cpp clang++ -g -O0 -shared -fPIC $$(llvm-config --cflags --cxxflags --ldflags --libs support mc) -o "$@" $^ -lclang .PHONY: run run: warnglobals.so clang++ -Xclang -load -Xclang ./warnglobals.so -Xclang -add-plugin -Xclang warn-globals test.cpp .PHONY: clean clean: -
sgielen revised this gist
Jan 29, 2014 . 1 changed file with 0 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,50 +5,6 @@ // // Written by John Bartholomew <jpa.bartholomew@gmail.com> #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" -
sgielen created this gist
Jan 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ warnglobals.so This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,110 @@ // -Wglobals Clang plugin // // Based on example plugins and searching Clang's API documentation. // BEWARE! This is my first ever attempt at a Clang plugin. // // Written by John Bartholomew <jpa.bartholomew@gmail.com> // Makefile #if 0 warnglobals.so: WarnGlobals.cpp clang++ -std=c++98 -shared -fPIC $$(llvm-config --cflags --libs support mc) -o "$@" $^ -L/usr/lib/llvm/ -lclang .PHONY: run run: warnglobals.so clang++ -fsyntax-only -Xclang -load -Xclang ./warnglobals.so -Xclang -plugin -Xclang warn-globals test.cpp .PHONY: clean clean: rm -f warnglobals.so #endif // TEST FILE -- copy out to test.cpp #if 0 #include <iostream> static int s_some_global = 42; static const int s_some_const_global = 42; static void some_function_with_a_static() { static int s_static_local = 42; } namespace some_namespace { namespace some_sub_namespace { int public_global = 42; } class some_class { static const int static_const_member = 42; static int static_member; }; } int some_namespace::some_class::static_member = 42; int main(int argc, char **argv) { std::cout << "global value: " << s_some_global << "\n"; return 0; } #endif #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Frontend/CompilerInstance.h" namespace { class PrintGlobalsVisitor : public clang::RecursiveASTVisitor<PrintGlobalsVisitor> { public: explicit PrintGlobalsVisitor(clang::ASTContext *Context, clang::DiagnosticsEngine *Diagnostics) : Context(Context), Diagnostics(Diagnostics) {} bool VisitVarDecl(clang::VarDecl *D) { const clang::SourceManager &SM = Context->getSourceManager(); if (D->hasGlobalStorage() && !D->getType().isConstQualified()) { clang::FullSourceLoc loc = Context->getFullLoc(D->getLocStart()); if (!SM.isInSystemHeader(loc)) { clang::DiagnosticsEngine &D = *Diagnostics; unsigned int id = D.getCustomDiagID(clang::DiagnosticsEngine::Warning, "global variable"); D.Report(loc, id); } } return true; } private: clang::ASTContext *Context; clang::DiagnosticsEngine *Diagnostics; }; class PrintGlobalsConsumer : public clang::ASTConsumer { public: explicit PrintGlobalsConsumer(clang::ASTContext *Context, clang::DiagnosticsEngine *Diagnostics) : Visitor(Context, Diagnostics) {} virtual void HandleTranslationUnit(clang::ASTContext &Context) { Visitor.TraverseDecl(Context.getTranslationUnitDecl()); } private: PrintGlobalsVisitor Visitor; }; class PrintGlobalsAction : public clang::PluginASTAction { protected: clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef) { return new PrintGlobalsConsumer(&CI.getASTContext(), &CI.getDiagnostics()); } bool ParseArgs(const clang::CompilerInstance &CI, const std::vector<std::string>& args) { // To be written... return true; } }; } static clang::FrontendPluginRegistry::Add<PrintGlobalsAction> X("warn-globals", "generate warnings for non-const global variables"); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ warnglobals.so: ClangWarnGlobals.cpp clang++ -g -O0 -std=c++98 -shared -fPIC $$(llvm-config --cflags --ldflags --libs support mc) -o "$@" $^ -lclang .PHONY: run run: warnglobals.so clang++ -Xclang -load -Xclang ./warnglobals.so -Xclang -plugin -Xclang warn-globals test.cpp .PHONY: clean clean: rm -f warnglobals.so This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ #include <iostream> static int s_some_global = 42; static const int s_some_const_global = 42; static void some_function_with_a_static() { static int s_static_local = 42; } namespace some_namespace { namespace some_sub_namespace { int public_global = 42; } class some_class { static const int static_const_member = 42; static int static_member; }; } int some_namespace::some_class::static_member = 42; int main(int argc, char **argv) { std::cout << "global value: " << s_some_global << "\n"; return 0; }