Giter VIP home page Giter VIP logo

clang-tutor's People

Contributors

banach-space avatar hftrader avatar ivafanas avatar lanza avatar samuelmarks avatar xgupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clang-tutor's Issues

Error happen when include STL header

Hi, author!
I recently work on implement new libtool based on clang-API, and I work on MacOSX-arm64 now, my environment is: LLVM version is 12.0.0, when I analyze a c++ code containing include<iostream>, libtool report error /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h:89:10: fatal error: 'stdarg.h' file not found. But clang could normally analyze this code. And there is stdarg.h in LLVM header search path, what should I do to fix this.

Questions about rationale of ASTMatcher and RecursiveASTVisitor?

Hi, author. Thanks for you excellent tutorial, I have some questions about your code in UnusedForLoopVar?

  • why ASTMatcher would work? you use API LoopVar->isUsed(true) in line 64 of UnusedForLoopVar.cpp to check whether LoopVar is used? how the attribute used of LoopVar is set to true. Does clang do this when it parse source code into AST?

  • you use API RecursiveASTVisitor::TraverseStmt(S->getBody()); instead of this->TraverseStmt(S->getBody()); in line 134 of UnusedForLoopVar.cpp, what's the difference between them.

No CMAKE_CXX_COMPILER could be found.

cmake -DCT_Clang_INSTALL_DIR=$Clang_DIR $CLANG_TUTOR_DIR/HelloWorld/ meet error


CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.16)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!

JIT related?

Great work!
So this tutor just focus on front-end? Will add some tutor about JIT of LLVM etc?
thanks

Example for instrumenting source code

Thank you! This is very helpful. Do you have any example plugins for adding functions to source code? I would like an example for adding a new function, with simple and complex variables(like structures ), which also uses inputs form the original source code. For example, an example plugin to ASTMatcher and Rewriter/Refactoring/Replacement tools in a plugin.

[IDEA] const-qualify tool

I want to work on a const qualify tool… concentrating on C with C++ as an afterthought (so don't want to get caught up on the constexpr, const ref, and const method conditions).

Whenever I go to a new codebase I'm [usually] annoyed at the lack of care taken to differentiate changing (var) names and unchanging (val/binding-only) names. Probably all those functional languages rubbing off on me!

I'd expect this to aid in compiler optimisations also…

So what I'm thinking is to use libclang and/or libtooling to modify code automatically from:

int f(int n) {
    int a = 5, b = 6, c;
    puts("nop");
    c = b;
    return n;
}

To:

const int f(const int n) {
    const int a = 5, b = 6;
    int c;
    puts("nop");
    c = b;
    return n;
}

…and get it to work nicely on enums, structs, objects (instantiations of classes and structs), functions, globals, and { scoped bodies (e.g., function bodies).

On the surface I'm not thinking this would be particularly difficult… at least for the majority of cases.

What do you think? - I don't have much experience here so happy to write it myself but could use some oversight 😅
(happy to release under CC0 to be compliant with your philosophy)

Thanks for your consideration

EDIT: Oh and I was watching this CppCon talk from a guy who made some progress in this direction: https://www.youtube.com/watch?v=tUBUqJSGr54

Run on Windows 11 Native

Work with conda-forge packages.
The following environment may be sufficient.

name: llvm

channels:
  - conda-forge
  - defaults

dependencies:

# build tools
- cmake
- conan 
- ninja
# - vcpkg

# https://github.com/conda-forge/clangdev-feedstock
- clang
- clang-format
# - clang-format-16
- clang-tools
- clangdev
# - clangxx
- libclang
- libclang-cpp
# - libclang-cpp16
# - libclang13
# - python-clang

# https://github.com/conda-forge/llvmdev-feedstock
- libllvm16
- lit
- llvm
- llvm-tools 
- llvmdev

As it is conda it should work for any platform.

I am working on a PR.

Fix building against LLVM/Clang configured with BUILD_SHARED_LIBS=ON

The tools from clang-tutor fail to build when using Clang/LLVM that was build with BUILD_SHARED_LIBS set. This is the error that I see on Ubuntu 16.04:

[7/9] Linking CXX executable bin/ct-la-commenter
FAILED: : && /usr/bin/clang++-11 -Wall    -fdiagnostics-color=always -fno-rtti -fvisibility-inlines-hidden -g  tools/CMakeFiles/ct-la-commenter.dir/LACommenterMain.cpp.o tools/CMakeFiles/ct-la-commenter.dir/__/lib/LACommenter.cpp.o -o bin/ct-la-commenter  -Wl,-rpath,/home/andwar02/work/release-11/build/release/lib  /home/bs/release-11/build/release/lib/libclangTooling.so.11  -Wl,-rpath-link,/home/bs/release-11/build/release/lib && :
/usr/bin/ld: tools/CMakeFiles/ct-la-commenter.dir/LACommenterMain.cpp.o: undefined reference to symbol '_ZN5clang14FrontendAction22shouldEraseOutputFilesEv'
/home/bs/work/release-11/build/release/lib/libclangFrontend.so.11: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)

SOLUTION 1
A solution was submitted by @xgupta here. It went through a few iterations. The original approach looked like this:

$ git diff
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 3673d81..6a33776 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -34,6 +34,14 @@ foreach( tool ${CLANG_TUTOR_TOOLS} )
     target_link_libraries(
       ${tool}
       clangTooling
+      clangFrontend
+      clangSerialization
+      clangRewrite
+      clangASTMatchers
+      clangAST
+      clangBasic
+      LLVMFrontendOpenMP
+      LLVMSupport
     )

     # Configure include directories for 'tool'

However, we discovered that that didn't work well with pre-build binary packages from Ubuntu 16.04. This is the error that I was getting at run-time:

 bin/ct-la-commenter <clang-tutor-dir>/test/LACBool.cpp 2>&1
: CommandLine Error: Option 'help-list' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted

So this was regression. It's hard to fix as it's not clear how the packages from Ubuntu are built and how to reproduce this with manually built packages.

SOLUTION 2
@xgupta kindly submitted an updated solution that is based on Clang's reference example. However, for this to work clang-tutor needs access to:

  • add_clang_executable
  • clang_target_link_libraries

This would normally be achieved with include(AddClang) in one of the CMake scripts. However, currently AddClang is not copied/installed in the build directory. A fix has been proposed here. One can also work around this by pointing clang-tutor to Clang's source directory (i.e. the location of AddClang). But that would mean that Ubuntu's pre-build packages alone are no longer sufficient to build the project.

SUMMARY
Both approaches break clang-tutor when using Ubuntu's pre-build LLVM/Clang packages. I think that SOLUTION 2 would be more canonical, but we may need for D94533 to be merged.

Visual Studio compiler lib import problem

1>HelloWorld.obj : error LNK2001: 无法解析的外部符号 "protected: virtual bool __cdecl clang::FrontendAction::shouldEraseOutputFiles(void)" (?shouldEraseOutputFiles@FrontendAction@clang@@MEAA_NXZ)
1>HelloWorld.obj : error LNK2001: 无法解析的外部符号 "protected: virtual void __cdecl clang::ASTFrontendAction::ExecuteAction(void)" (?ExecuteAction@ASTFrontendAction@clang@@MEAAXXZ)
1>HelloWorld.obj : error LNK2001: 无法解析的外部符号 "private: virtual void __cdecl clang::PluginASTAction::anchor(void)" (?anchor@PluginASTAction@clang@@EEAAXXZ)
1>HelloWorld.obj : error LNK2019: 无法解析的外部符号 "public: __cdecl clang::FrontendAction::FrontendAction(void)" (??0FrontendAction@clang@@QEAA@XZ),函数 "class std::unique_ptr<class FindNamedClassAction,struct std::default_delete<class FindNamedClassAction> > __cdecl std::make_unique<class FindNamedClassAction,0>(void)" (??$make_unique@VFindNamedClassAction@@$$V$0A@@std@@YA?AV?$unique_ptr@VFindNamedClassAction@@U?$default_delete@VFindNamedClassAction@@@std@@@0@XZ) 中引用了该符号
1>HelloWorld.obj : error LNK2019: 无法解析的外部符号 "public: virtual __cdecl clang::FrontendAction::~FrontendAction(void)" (??1FrontendAction@clang@@UEAA@XZ),函数 "public: virtual void * __cdecl FindNamedClassAction::`scalar deleting destructor'(unsigned int)" (??_GFindNamedClassAction@@UEAAPEAXI@Z) 中引用了该符号
1>HelloWorld.obj : error LNK2019: 无法解析的外部符号 "public: static void __cdecl llvm::Registry<class clang::PluginASTAction>::add_node(class llvm::Registry<class clang::PluginASTAction>::node *)" (?add_node@?$Registry@VPluginASTAction@clang@@@llvm@@SAXPEAVnode@12@@Z),函数 "void __cdecl `dynamic initializer for 'X''(void)" (??__EX@@YAXXZ) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPDirectiveName(enum llvm::omp::Directive)" (?getOpenMPDirectiveName@omp@llvm@@YA?AVStringRef@2@W4Directive@12@@Z),函数 "public: void __cdecl clang::OMPClausePrinter::VisitOMPIfClause(class clang::OMPIfClause *)" (?VisitOMPIfClause@OMPClausePrinter@clang@@QEAAXPEAVOMPIfClause@2@@Z) 中引用了该符号
1>clangAST.lib(StmtPrinter.obj) : error LNK2001: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPDirectiveName(enum llvm::omp::Directive)" (?getOpenMPDirectiveName@omp@llvm@@YA?AVStringRef@2@W4Directive@12@@Z)
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "enum llvm::omp::TraitSet __cdecl llvm::omp::getOpenMPContextTraitSetForProperty(enum llvm::omp::TraitProperty)" (?getOpenMPContextTraitSetForProperty@omp@llvm@@YA?AW4TraitSet@12@W4TraitProperty@12@@Z),函数 "public: void __cdecl clang::OMPTraitInfo::getAsVariantMatchInfo(class clang::ASTContext &,struct llvm::omp::VariantMatchInfo &)const " (?getAsVariantMatchInfo@OMPTraitInfo@clang@@QEBAXAEAVASTContext@2@AEAUVariantMatchInfo@omp@llvm@@@Z) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPContextTraitSetName(enum llvm::omp::TraitSet)" (?getOpenMPContextTraitSetName@omp@llvm@@YA?AVStringRef@2@W4TraitSet@12@@Z),函数 "public: void __cdecl clang::OMPTraitInfo::print(class llvm::raw_ostream &,struct clang::PrintingPolicy const &)const " (?print@OMPTraitInfo@clang@@QEBAXAEAVraw_ostream@llvm@@AEBUPrintingPolicy@2@@Z) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPContextTraitSelectorName(enum llvm::omp::TraitSelector)" (?getOpenMPContextTraitSelectorName@omp@llvm@@YA?AVStringRef@2@W4TraitSelector@12@@Z),函数 "public: void __cdecl clang::OMPTraitInfo::print(class llvm::raw_ostream &,struct clang::PrintingPolicy const &)const " (?print@OMPTraitInfo@clang@@QEBAXAEAVraw_ostream@llvm@@AEBUPrintingPolicy@2@@Z) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "enum llvm::omp::TraitProperty __cdecl llvm::omp::getOpenMPContextTraitPropertyKind(enum llvm::omp::TraitSet,class llvm::StringRef)" (?getOpenMPContextTraitPropertyKind@omp@llvm@@YA?AW4TraitProperty@12@W4TraitSet@12@VStringRef@2@@Z),函数 "public: __cdecl clang::OMPTraitInfo::OMPTraitInfo(class llvm::StringRef)" (??0OMPTraitInfo@clang@@QEAA@VStringRef@llvm@@@Z) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPContextTraitPropertyName(enum llvm::omp::TraitProperty)" (?getOpenMPContextTraitPropertyName@omp@llvm@@YA?AVStringRef@2@W4TraitProperty@12@@Z),函数 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl clang::OMPTraitInfo::getMangledName(void)const " (?getMangledName@OMPTraitInfo@clang@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 中引用了该符号
1>clangAST.lib(OpenMPClause.obj) : error LNK2019: 无法解析的外部符号 "bool __cdecl llvm::omp::isValidTraitSelectorForTraitSet(enum llvm::omp::TraitSelector,enum llvm::omp::TraitSet,bool &,bool &)" (?isValidTraitSelectorForTraitSet@omp@llvm@@YA_NW4TraitSelector@12@W4TraitSet@12@AEA_N2@Z),函数 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl clang::OMPTraitInfo::getMangledName(void)const " (?getMangledName@OMPTraitInfo@clang@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 中引用了该符号
1>clangAST.lib(StmtPrinter.obj) : error LNK2019: 无法解析的外部符号 "public: static class llvm::StringRef __cdecl clang::Lexer::getSourceText(class clang::CharSourceRange,class clang::SourceManager const &,class clang::LangOptions const &,bool *)" (?getSourceText@Lexer@clang@@SA?AVStringRef@llvm@@VCharSourceRange@2@AEBVSourceManager@2@AEBVLangOptions@2@PEA_N@Z),函数 "bool __cdecl printExprAsWritten(class llvm::raw_ostream &,class clang::Expr *,class clang::ASTContext const *)" (?printExprAsWritten@@YA_NAEAVraw_ostream@llvm@@PEAVExpr@clang@@PEBVASTContext@4@@Z) 中引用了该符号
1>clangAST.lib(Expr.obj) : error LNK2019: 无法解析的外部符号 "public: __cdecl clang::Lexer::Lexer(class clang::SourceLocation,class clang::LangOptions const &,char const *,char const *,char const *)" (??0Lexer@clang@@QEAA@VSourceLocation@1@AEBVLangOptions@1@PEBD22@Z),函数 "public: class clang::SourceLocation __cdecl clang::StringLiteral::getLocationOfByte(unsigned int,class clang::SourceManager const &,class clang::LangOptions const &,class clang::TargetInfo const &,unsigned int *,unsigned int *)const " (?getLocationOfByte@StringLiteral@clang@@QEBA?AVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@AEBVTargetInfo@2@PEAI3@Z) 中引用了该符号
1>clangAST.lib(Expr.obj) : error LNK2019: 无法解析的外部符号 "private: bool __cdecl clang::Lexer::Lex(class clang::Token &)" (?Lex@Lexer@clang@@AEAA_NAEAVToken@2@@Z),函数 "public: class clang::SourceLocation __cdecl clang::StringLiteral::getLocationOfByte(unsigned int,class clang::SourceManager const &,class clang::LangOptions const &,class clang::TargetInfo const &,unsigned int *,unsigned int *)const " (?getLocationOfByte@StringLiteral@clang@@QEBA?AVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@AEBVTargetInfo@2@PEAI3@Z) 中引用了该符号
1>clangAST.lib(Expr.obj) : error LNK2019: 无法解析的外部符号 "public: static unsigned int __cdecl clang::Lexer::getTokenPrefixLength(class clang::SourceLocation,unsigned int,class clang::SourceManager const &,class clang::LangOptions const &)" (?getTokenPrefixLength@Lexer@clang@@SAIVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@@Z),函数 "public: class clang::SourceLocation __cdecl clang::StringLiteral::getLocationOfByte(unsigned int,class clang::SourceManager const &,class clang::LangOptions const &,class clang::TargetInfo const &,unsigned int *,unsigned int *)const " (?getLocationOfByte@StringLiteral@clang@@QEBA?AVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@AEBVTargetInfo@2@PEAI3@Z) 中引用了该符号
1>clangAST.lib(Expr.obj) : error LNK2019: 无法解析的外部符号 "public: unsigned int __cdecl clang::StringLiteralParser::getOffsetOfStringByte(class clang::Token const &,unsigned int)const " (?getOffsetOfStringByte@StringLiteralParser@clang@@QEBAIAEBVToken@2@I@Z),函数 "public: class clang::SourceLocation __cdecl clang::StringLiteral::getLocationOfByte(unsigned int,class clang::SourceManager const &,class clang::LangOptions const &,class clang::TargetInfo const &,unsigned int *,unsigned int *)const " (?getLocationOfByte@StringLiteral@clang@@QEBA?AVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@AEBVTargetInfo@2@PEAI3@Z) 中引用了该符号
1>clangAST.lib(Expr.obj) : error LNK2019: 无法解析的外部符号 "private: void __cdecl clang::StringLiteralParser::init(class llvm::ArrayRef<class clang::Token>)" (?init@StringLiteralParser@clang@@AEAAXV?$ArrayRef@VToken@clang@@@llvm@@@Z),函数 "public: class clang::SourceLocation __cdecl clang::StringLiteral::getLocationOfByte(unsigned int,class clang::SourceManager const &,class clang::LangOptions const &,class clang::TargetInfo const &,unsigned int *,unsigned int *)const " (?getLocationOfByte@StringLiteral@clang@@QEBA?AVSourceLocation@2@IAEBVSourceManager@2@AEBVLangOptions@2@AEBVTargetInfo@2@PEAI3@Z) 中引用了该符号
1>clangAST.lib(TextNodeDumper.obj) : error LNK2019: 无法解析的外部符号 "class llvm::StringRef __cdecl llvm::omp::getOpenMPClauseName(enum llvm::omp::Clause)" (?getOpenMPClauseName@omp@llvm@@YA?AVStringRef@2@W4Clause@12@@Z),函数 "public: void __cdecl <lambda_9a749cc2600948731067c16499d3e43b>::operator()(void)const " (??R<lambda_9a749cc2600948731067c16499d3e43b>@@QEBAXXZ) 中引用了该符号
1>clangAST.lib(JSONNodeDumper.obj) : error LNK2019: 无法解析的外部符号 "public: static unsigned int __cdecl clang::Lexer::MeasureTokenLength(class clang::SourceLocation,class clang::SourceManager const &,class clang::LangOptions const &)" (?MeasureTokenLength@Lexer@clang@@SAIVSourceLocation@2@AEBVSourceManager@2@AEBVLangOptions@2@@Z),函数 "private: void __cdecl clang::JSONNodeDumper::writeBareSourceLocation(class clang::SourceLocation,bool)" (?writeBareSourceLocation@JSONNodeDumper@clang@@AEAAXVSourceLocation@2@_N@Z) 中引用了该符号
1>clangAST.lib(CommentSema.obj) : error LNK2019: 无法解析的外部符号 "public: class llvm::StringRef __cdecl clang::Preprocessor::getLastMacroWithSpelling(class clang::SourceLocation,class llvm::ArrayRef<class clang::TokenValue>)const " (?getLastMacroWithSpelling@Preprocessor@clang@@QEBA?AVStringRef@llvm@@VSourceLocation@2@V?$ArrayRef@VTokenValue@clang@@@4@@Z),函数 "public: void __cdecl clang::comments::Sema::checkDeprecatedCommand(class clang::comments::BlockCommandComment const *)" (?checkDeprecatedCommand@Sema@comments@clang@@QEAAXPEBVBlockCommandComment@23@@Z) 中引用了该符号

What's the difference between TraverseForStmt and VisitForStmt?

Hi,

I am learning the excellent tutorial, and I have some confusion in UnusedForLoopVar Tool. In UnusedForLoopVar especially in the implementation of RecursiveASTVisitor, the TraverseForStmt() is used to visit the ForStmt in AST, rather than VisitForStmt(). What's the difference between these two methods on visiting the AST nodes? Why would UnusedForLoopVar use TraverseForStmt() rather than VisitForStmt()?

Thank you very much!!!

Obfuscator output is weird for the input with both + and - operations

Please consider the following input file:

int foo(int a, int b) {
  return a + b;
}

int bar(int a, int b) {
  return a - b;
}

Actual obfuscator plugin output is:

int foo(int a, int b) {
  return (a ^ b) + 2 * (a & b);
}

int bar(int a, int b) {
  return a - b;
}

int foo(int a, int b) {
  return a + b;
}

int bar(int a, int b) {
  return (a + ~b) + 1;
}

Expected obfuscator plugin output is:

int foo(int a, int b) {
  return (a ^ b) + 2 * (a & b);
}

int bar(int a, int b) {
  return (a + ~b) + 1;
}

May be it is possible to share Rewriter between matchers and apply rewrite at the end of ObfuscatorASTConsumer::HandleTranslationUnit call

[IDEA] Convert types to correct ones: `for(int i=0; i<vec.size(); i++)` => `for(size_t i=0; i<vec.size(); i++)`

Often when building third-party libraries I get a bunch of warnings "comparison between signed and unsigned types is UB".

Not every such occurrence has a trivial solution. But—in my experience—most do. Usually switching just one var from int to size_t also requires tracing all use of that var and changing all those types to size_t also.

From:

unsigned long f() {return 0;}
const size_t v = f();

int main() {
    std::vector<float> vec;
    for(int i=0; i<vec.size(); i++) {}
}

To:

unsigned long f() {return 0;}
const unsigned long v = f();

int main() {
    std::vector<float> vec;
    for(int i=0; i<vec.size(); i++) {}
}

PS: I'm aware that size_type isn't necessarily size_t… but using it here anyway. Just to reiterate: C++ is an afterthought, my main target is C.

Having this tool may aid in compiler optimisation, will reduce UB, and draw down the number of warnings.

Happy to build it myself and release it under CC0 to be compatible with your philosophy. But I'm new to all this, so would benefit from your insights/aid.

How about it? 😃

Thanks for your consideration

Windows build fails to work with clang++

I have the weirdest issue. I have followed your clang-tutor and your llvm-tutor pages - great effort and very informative! Since in llvm-tutor there is a windows version for the project cmake file, I thought I could build your hello plugin on windows too. I managed to get something to build, but it only works with the -cc1 command, not with the -Xclang version. Furthermore, it only seems to work with clang.exe, couldn't get it to work with clang++.exe. I am probably doing something very wrong.

There are 2 things I have tried, when it comes to making the cmake file work: at first, I tried to make your cmake file work. It doesn't quite work out of the box. When cmake generates a visual studio solution, it links (correctly) the needed libs to the project, but also tries to find a "clang.lib", to no avail. When building LLVM/Clang (12), this library seems to stay in the build directory and not get copied over when cmake executes the install target. Fair enough, I just manually linked the odd one out clang.lib from the original build directory. Now the plugin compiles & works, but only with clang.exe and -cc1.

Second thing I tried, is that, on windows, this clang.lib is all that is needed for the linker, to build the plugin. All the libs in the llvm install dir/lib are unnecessary (so it would seem?). So I could build the whole hello plugin with just clang.lib and the include dirs at the install/include. However, the plugin still only works when called from clang.exe with -cc1.

Have you tried making hello plugin work on windows? Do you have any insight into why a plugin would run correctly with -cc1 and not with Xclang? Or with clang.exe but not with clang++.exe?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.