Giter VIP home page Giter VIP logo

flycheck-clang-analyzer's Introduction

Flycheck Clang Static Analyzer (scan-build) Checker

License GPL 3 MELPA Build Status

Integrate Clang Static Analyzer (aka. scan-build) with flycheck to automatically perform on-the-fly static analysis as you code.

flycheck-clang-analyzer screenshot

This package leverages the configuration of the existing c/c++-clang flycheck checker, or either emacs-cquery, emacs-ccls, irony-mode or rtags to provide the appropriate compiler flags for clang - and so requires zero extra setup. This checker also automatically chains itself as the next flycheck checker after c/c++-clang, lsp-ui flycheck-irony and flycheck-rtags so that it only runs when the corresponding previous checker returns without warnings. This avoids trying to perform the analysis when there are syntactic errors etc.

Installation

MELPA

The preferred way to install flycheck-clang-analyzer is via MELPA - then you can just M-x package-install RET flycheck-clang-analyzer RET

To enable then simply add the following to your init file:

(with-eval-after-load 'flycheck
  (require 'flycheck-clang-analyzer)
  (flycheck-clang-analyzer-setup))

We recommend to use use-package to make this automatic:

(use-package flycheck-clang-analyzer
  :ensure t
  :after flycheck
  :config (flycheck-clang-analyzer-setup))

Manual

If you would like to install the package manually, download or clone it and place it within Emacs' load-path, then you can require it in your init file like this:

(require 'flycheck-clang-analyzer)
(flycheck-clang-analyzer-setup)

NOTE: This will also require the manual installation of flycheck if you have not done so already.

Configuration

This should work with zero configuration, since we try and leverage the configuration of existing clang-based Flycheck checkers.

The only configuration option is flycheck-clang-analyzer-executable which is the path to the clang executable - this defaults to clang. However if you need to change this to something else, simply setq it as appropriate before calling (flycheck-clang-analyzer-setup) - so to set to use clang-3.8 instead of clang:

(setq flycheck-clang-analyzer-executable "clang-3.8")
(flycheck-clang-analyzer-setup)

License

Copyright © 2018 Alex Murray

Distributed under GNU GPL, version 3.

flycheck-clang-analyzer's People

Contributors

alexmurray avatar dreac0nic 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

Watchers

 avatar  avatar  avatar  avatar  avatar

flycheck-clang-analyzer's Issues

Just trying to understand the added value of this package.

Given the following setup, how is this package adding extra value?

  1. llvm/clang installed
  2. irony-mode
  3. flycheck and irony-flycheck.

I can already see programming errors on the fly, so I am not sure how is the clang-analyzer any different?

I get a "suspicious state" error

I see this being reported in the minibuffer when opening a C file:

Suspicious state from syntax checker clang-analyzer: Flycheck checker clang-analyzer returned non-zero exit code 1, but its output contained no errors: In file included from /home/user/testinit.c:327:

-fcolor-diagnostics not supported

Parsing the compile options does not work when -fcolor-diagnostics is present in the compilation databases.

This code try to fix this:

  :command ("clang"
	    "-fno-color-diagnostics" ; don't include color in output
	    "-fno-caret-diagnostics" ; don't indicate location in output
	    "-fno-diagnostics-show-option" ; don't show warning group
	    "--analyze"
	    (eval (flycheck-clang-analyzer--get-compile-options))
            source-inplace)

However, this code adds the -fno-color-diagnostics option BEFORE the compilation database options,
it should add it AFTER so that the compilation database is overriden.

.plist and .gch files are populating my repo

Hi Alex,
I started noticing flycheck files in the source and header directories. For c files they have the extension .plist and for the headers .gch:
flycheck_source.plist
flycheck_header.gch

I noticed them because they show up before I make commits and I have to go delete them manually before pushing my changes to the main repo.

I also noticed that these files are generated only when flycheck-clang-analyzer is enabled. Is there a way to disable generating these files?

"Cannot use syntax checker clang-analyzer in this buffer"

Hello,

Everything works as expected in a minimal example of

#include <stdio.h>
#include <limits>
#include <stdlib.h>


int main() {
  void *p = malloc(1000);
  return 0;
}

But when I try it on an actual project, it is not working. I am using irony and rtags on the same codebase and a .clang_completion and a compile_commands.json file is at the root of the source tree.

If I navigate to a .cxx of this project and run flycheck-compile with clang-analyzer I merely get "Cannot use syntax checker clang-analyzer in this buffer" in the message-buffer. I know this is very sparse information, but am unsure about how to debug this problem further. Any hints would be greatly appreciated!

Wrong URL in flycheck-define-checker call

When defining the checker in flycheck-define-checker, the url of the project is set to https://github.com/alexmurray/clang-analyzer/. (line 218 of flycheck-clang-analyzer.el on my machine)

It should be changed to https://github.com/alexmurray/flycheck-clang-analyzer/

Broken filtering of compilation flags from RTags

flycheck-clang-analyzer--rtags-get-compile-options uses rtags-compilation-flags to get the compilation flags and then filters them through flycheck-clang-analyzer--valid-compilation-flag-p.

Depending on how you look at it, the implementation of flycheck-clang-analyzer--valid-compilation-flag-p is either very naive, or rtags-compilation-flags doesn't do the right thing.

I have filed issue Andersbakken/rtags#1223 to see what RTags has to say about it, but I'll repeat some of that here.

Say you have:
clang++ -isystem /foo -iquote /bar -fsanitize=address,undefined -c -o my.o my.cpp
then rtags-compilation-flags will give you:

clang++
-isystem
/foo
-iquote
/bar
-fsanitize=address,undefined
-c
-o
my.o
my.cpp

while flycheck-clang-analyzer--valid-compilation-flag-p seems to expect:

clang++
-isystem /foo
-iquote /bar
-fsanitize=address,undefined
-c
-o my.o
my.cpp

As RTags does it today, flycheck-clang-analyzer--valid-compilation-flag-p will remove /foo and /bar while leaving -isystem and -iquote as standalone flags. And it will remove -o, but leave the name of the output file. Needless to say that this then makes flycheck-clang-analyzer fail.

If RTags decides to change its output, then this problem will go away for newer versions.

If not (and for older version), perhaps flycheck-clang-analyzer--valid-compilation-flag-p could be made more forgiving? Perhaps rewriting it to be more of a filter function instead that removes -c and -o, taking into account that those entries may or may not contain a filename. And if not, that the next option may be a filename.

Unable to use ccls as backend

The function ccls--is-ccls-buffer has been removed in this commit. This causes the ccls backend to be reported as inactive and only the fallback solution will be used.

Spacemacs: "Flycheck cannot use this syntax checker for this buffer"

Hello,

I have been trying to include this package in my spacemacs config. I undertook the following steps:

  • put flycheck-clang-analyzer in dotspacemacs-additional-packages
  • add the config to dotspacemacs/user-config:
(use-package flycheck-clang-analyzer
  :ensure t
  :after flycheck
  :config (flycheck-clang-analyzer-setup))

However, when trying to select clang-analyzer as checker, an error occured:

Syntax checker in buffer hello_world.h in c++-mode:

  clang-analyzer
    - major mode: `c++-mode' supported
    - may enable: yes
    - predicate:  nil
    - executable: Found at /usr/bin/clang
    - Backend:    flycheck-clang

Flycheck cannot use this syntax checker for this buffer.

Flycheck Mode is enabled. Use SPC u C-c ! x to enable disabled checkers.

--------------------

Flycheck version: 32snapshot (package: 20190311.1422)
Emacs version:    26.1
System:           x86_64-pc-linux-gnu
Window system:    x

It would be very helpful if someone can shed some light on this issue. Thanks!

Use compilation database in project root

I am wondering if its possible to configure flycheck-clang-analyzer to pass arguments to clang to tell it to read compile_commands.json in the project root directory. Configuring static arguments seems straightforward, but I would ideally like to determine the project root directory on the fly (e.g. using projectile) and tell clang to look there for the compilation database. Any suggestions would be much appreciated.

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.