What is the best way to get the emitted compilation warnings and errors in a structured format (e.g. XML file, or similar) when using clang?
I'm aware of the command line option --serialize-diagnostics, but the serialized data format is binary and I found no description how to decode it.
My other option would be to write a clang plugin that can emit the warnings and errors by itself into e.g. XML.
What other options I have? Text parsing is not an option for me, I'd need the structured data right from clang.
Related
I'm using the python bindings to walk the clang AST...
When I encounter an error, I would like to dump the AST to a file, so that I can later load it from that file and debug the walker.
This works fine, if I dump and then load using the TranslationUnit.save() and Index.read() bindings, however this does not work if I move the AST file between platforms Linux -> Windows or Windows -> Linux.
Is this expected?
Is there a way to make the AST files "portable"?
Not "portable" if you have some template C++ code that is accepted by MSVC, but typically diagnosed by Clang as invalid.
From Clang Documentation:
Third, MSVC accepts some C++ code that Clang will typically diagnose as invalid. When these constructs are present in widely included system headers, Clang attempts to recover and continue compiling the user’s program. Most parsing and semantic compatibility tweaks are controlled by -fms-compatibility and -fdelayed-template-parsing, and they are a work in progress.
Compare your saved AST files to check if they have the same nodes (the raw pointer address could be different). If not, fixed with the mentioned flags -fms-compatibility, -fdelayed-template-parsing.
I am compiling a fairly large library with many outside dependencies that I need to pull in. Each time I attempt a compilation I get a new error about a missing header file. I then have to go and track down where to find that header/library and add it to the project includes. This process of compilation-then-find-header/source is repeated and takes a lot of time.
I would like the compiler to continue trying to build and output all missing headers in one error list. Is this possible using Clang and if so how can I control it? On a related note, once I have all headers is it possible to tell Clang to report all linker errors/undefined references, so I don't have to repeat this process with source files?
I am looking for compiler flags to print out all possible errors (missing headers) and all undefined references. In other words, I want the compilation to continue passed the first file with errors and attempt to compile all files in the project. The compiler is Clang (C/C++) version 8.0.2. The make tool is ninja (1.5.3). Make files are generated with CMake (3.6.4).
Update:
Looking back, my original question was asking for a solution in the wrong tool. Instead of passing a flag to Clang, I needed to pass a flag to my make tool, Ninja.
From ninja --help:
-k N keep going until N jobs fail [default=1]
so i'd run ninja command like:
ninja -k 100
to continue until 100 errors are found or the build succeeds. One thing to note is that some errors may just stop the entire build if the erroneous file is necessary to continue the build process.
I'm trying to move a cross-compiled CMake project to Clang Modules to see whether compile time reduction is worth it. However, it seems that Clang is generating lots of duplicate modules in it's ModuleCache.
I'd like to figure out why (maybe some CMake config, etc), so I'm trying to run clang -module-file-info on the generated module files.
However, clang's output is just empty whenever I provide a proper module file. Am I doing anything wrong? Is there anything special that I need to take care of?
The files all have a reasonable size (from a few kB to a few MB), look fine in a Hex editor (start with CPCH, have some recognizable strings, etc) and whenever I specify a wrong file (or a file compiled with a different version of clang) I get the appropriate errors.
I've tried with clang 7.0.1 as well as 8.0.0.
I also tried --verbose but that didn't show any problems either.
To answer my own question:
clang doesn't output the stats on the command line, it puts it into a file by default written in the current directory.
I'm writing a tool that uses clang CompilerInstance and ParseAST to parse and rewrite a source file. What I find quite annoying is that if include paths are missing then the tool outputs an error that it can not find some include file, however the AST is still being built and my tool works just fine. What I would like to do is tell clang to not report an error when an include file is missing and to just parse the AST and let me rewrite the code in just that file.
Is there an example that shows how to do this?
My code is based on the CIrewriter.cpp example from github.https://github.com/loarabia/Clang-tutorial/blob/master/CIrewriter.cpp
I'd like to convert a CMake-based C++ library to bazel.
As part of the current CMake project, I'm using a libclang-based code generator that parses C++ headers and generates C++ code from the parsed AST. In order to do that, I need the actual compiler flags used to build the cc_library the header is part of. The flags are passed to the code generation tool so it can use clang's preprocessor.
Is there any way I could access the compiler flags used to build a dependency from a skylark- or gen_rule rule? I'm particularly interested in the include paths and defines.
We're working on it. Well, not right now, but will soon. You might want to subscribe to the corresponding issue, and maybe describe your requirements there so we take them into account when designing the API.