tbricks / itiviti-cpp-analyzer Goto Github PK
View Code? Open in Web Editor NEWClang plugin with several static analysis checks
License: BSD 2-Clause "Simplified" License
Clang plugin with several static analysis checks
License: BSD 2-Clause "Simplified" License
There are several versions of clang being used around there, with corresponding libclang versions. Libclang is not backward compatible, thus, migration to a new version would either force to support ICA on both versions or to abandon older clang support
Making it standalone (ideally, statically-linked) executable would give much more freedom for developers to base on any libclang version they want and for users to not maintain their clang and ica versions synced
Passing -plugin-arg-ica-plugin checks=redundant-noexcept -plugin-arg-ica-plugin checks=improper-move
will actually only enable improper-move
checks. I believe that this should be handled in the same way as -plugin-arg-ica-plugin checks=redundant-noexcept,improper-move
.
From the user perspective, I am thinking about following use-case:
add_ica_checks(all)
target_ica_checks(foo PRIVATE -redundant-noexcept)
This should run foo
compilation with all checks but redundant-noexcept
. Right now, this does not enable any check at all for foo
, since ICA sees this as checks=-redundant-noexcept
.
Analyzer suggests constructing m_significand in the initializer list
// int64_t m_significand & int64_t m_exponent are private fields of struct Exponential
Exponential::Exponential(int64_t number)
: m_significand(number)
, m_exponent(0)
{
while (m_significand != 0 && m_significand % 10 == 0) {
++m_exponent;
m_significand /= 10;
}
}
[ 6%] Building CXX object CMakeFiles/expressions_lib.dir/src/exponential.cpp.o
error: 'm_significand' can be constructed in initializer list
m_significand /= 10;
^
Analyzer suggest adding 'const' qualifier for mutable std::bitset instance that changes in the for-loop.
foo.h
#include <bitset>
struct A {
static const int length = 128;
static void bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start = 0, int b_start = 0);
}
foo.cpp
void A::bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start, int b_start)
{
for (int i = a_start, j = b_start; i < A::length && j < A::length; ++i, ++j) {
int sum = static_cast<int>(a[i]) + static_cast<int>(b[j]);
a[i] = static_cast<bool>(sum % 2);
}
}
[ 5%] Building CXX object CMakeFiles/expressions_lib.dir/src/foo.cpp.o
error: 'a' can have 'const' qualifier [const-param]
void A::bar(std::bitset<length> & a, const std::bitset<length> & b, int a_start, int b_start)
^
1 error generated.
Clang 11.0.0
When a member function tries to modify some fields of a dereferenced field of its argument passed by non-const reference, we get a [const-param]
warning that suggests to make such argument const
.
struct Node
{
void update(Node & parent) // no warning expected
{
if (parent.left != nullptr) {
parent.left->parent = &parent;
}
}
Node * left;
Node * right;
Node * parent;
};
[ 50%] Building CXX object CMakeFiles/ica_test.dir/main.cpp.o
/usr/bin/c++ -g -Xclang -plugin-arg-ica-plugin -Xclang checks=all=err -Xclang -load -Xclang /usr/local/lib/libica-plugin.so -Xclang -add-plugin -Xclang ica-plugin -std=gnu++17 -o CMakeFiles/ica_test.dir/main.cpp.o -c /home/imodre/CLionProjects/ica-test/main.cpp
/home/imodre/CLionProjects/ica-test/main.cpp:3:17: error: 'parent' can have 'const' qualifier [const-param]
void update(Node & parent) // no warning expected
^
1 error generated.
Default build from master branch of this repo, clang 10
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.