Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
xjia1 committed Dec 20, 2023
1 parent 941fc56 commit 9694d41
Show file tree
Hide file tree
Showing 906 changed files with 10,793 additions and 4,128 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ all:
$(MAKE) out/bin/infer

PRUNE_AND_FIND := find . \( -path ./third_party \
-o -path ./build/output \
-o -path ./clang-tidy \
-o -path ./misra_c_2012 \
-o -path ./out \
-o -path ./podman_image/tmpWorkSpace \
-o -path ./vm \
-o -path ./vscode/nsa-result-highlight/analyze-demo \
-o -path '*/_bad0*' -o -path '*/_good00*' \
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ directly from the source code.

### Using prebuilt container images

Refer to [analyze-demo](https://github.com/naivesystems/analyze-demo) for an example.
Refer to [analyze-demo](https://github.com/naivesystems/analyze-demo) for an
example.

For projects using Makefiles, run the commands below in your project root:

Expand All @@ -43,7 +44,7 @@ podman run --rm \
-v $PWD:/src:O \
-v $PWD/.naivesystems:/config:Z \
-v $PWD/output:/output:Z \
ghcr.io/naivesystems/analyze:2023.3.3.0 \
ghcr.io/naivesystems/analyze:latest \
/opt/naivesystems/misra_analyzer -show_results
```

Expand All @@ -65,7 +66,7 @@ A few notes:

* You may remove `:Z` if you are not using SELinux.

* Replace `2023.3.3.0` with the actual version that you want to use.
* Replace `latest` with the actual version that you want to use.

NaiveSystems Analyze can trace and capture your build process automatically.
Currently we only publish Fedora-based images in the Community Edition, so your
Expand All @@ -92,7 +93,7 @@ information.

### Building from source

To build from source, follow the steps below on Fedora 36 or 37. Other versions
To build from source, follow the steps below on Fedora 37. Other versions
may also work but are not officially supported in the Community Edition.

1. Install build dependencies
Expand Down
4 changes: 2 additions & 2 deletions analyzer/proto/analyzer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ message Definitions {
}

message CheckerConfiguration {
// System library options for CSA checker.
string csa_system_lib_options = 1;
string infer_bin = 2;
string clang_bin = 3;
string code_checker_bin = 4;
reserved 4;
string cppcheck_bin = 5;
string python_bin = 6;
string clangtidy_bin = 7;
Expand All @@ -65,4 +64,5 @@ message CheckerConfiguration {
string clangmapping_bin = 13;
int64 infer_jobs = 14;
string cpplint_script = 15;
reserved 16;
}
18 changes: 18 additions & 0 deletions analyzer/proto/results.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ message Result {
MISRA_C_2012_RULE_5_9 = 1050901;
MISRA_C_2012_RULE_6_1 = 1060100;
MISRA_C_2012_RULE_6_2 = 1060200;
MISRA_C_2012_RULE_6_3 = 1060301;
MISRA_C_2012_RULE_7_1 = 1070100;
MISRA_C_2012_RULE_7_2 = 1070200;
MISRA_C_2012_RULE_7_3 = 1070300;
MISRA_C_2012_RULE_7_4_CPPCHECK = 1070400;
MISRA_C_2012_RULE_7_4 = 1070401;
MISRA_C_2012_RULE_7_4_EXTERNAL = 1070402;
MISRA_C_2012_RULE_7_5 = 1070501;
MISRA_C_2012_RULE_8_1 = 1080100;
MISRA_C_2012_RULE_8_2_FUNC_DECL_PARM_NOT_NAMED_ERROR = 1080201;
MISRA_C_2012_RULE_8_2_FUNC_POINTER_PARM_NOT_NAMED_ERROR = 1080202;
Expand All @@ -123,6 +125,9 @@ message Result {
MISRA_C_2012_RULE_8_11 = 1081100;
MISRA_C_2012_RULE_8_12 = 1081200;
MISRA_C_2012_RULE_8_14 = 1081400;
MISRA_C_2012_RULE_8_15 = 1081501;
MISRA_C_2012_RULE_8_16 = 1081601;
MISRA_C_2012_RULE_8_17 = 1081701;
MISRA_C_2012_RULE_9_1 = 1090101;
MISRA_C_2012_RULE_9_2 = 1090200;
MISRA_C_2012_RULE_9_3 = 1090300;
Expand Down Expand Up @@ -203,6 +208,10 @@ message Result {
MISRA_C_2012_RULE_17_7 = 1170700;
MISRA_C_2012_RULE_17_8_CPPCHECK = 1170800;
MISRA_C_2012_RULE_17_8 = 1170801;
MISRA_C_2012_RULE_17_9 = 1170901;
MISRA_C_2012_RULE_17_10 = 1171001;
MISRA_C_2012_RULE_17_12 = 1171201;
MISRA_C_2012_RULE_17_13 = 1171301;
MISRA_C_2012_RULE_18_1 = 1180101;
MISRA_C_2012_RULE_18_2 = 1180201;
MISRA_C_2012_RULE_18_3 = 1180301;
Expand Down Expand Up @@ -240,6 +249,7 @@ message Result {
MISRA_C_2012_RULE_21_10 = 1211000;
MISRA_C_2012_RULE_21_11 = 1211100;
MISRA_C_2012_RULE_21_12 = 1211200;
MISRA_C_2012_RULE_21_12_AMD3 = 1211210;
MISRA_C_2012_RULE_21_13 = 1211301;
MISRA_C_2012_RULE_21_14 = 1211401;
MISRA_C_2012_RULE_21_15 = 1211500;
Expand All @@ -251,6 +261,9 @@ message Result {
MISRA_C_2012_RULE_21_19_EXTERNAL = 1211902;
MISRA_C_2012_RULE_21_20 = 1212001;
MISRA_C_2012_RULE_21_21 = 1212100;
MISRA_C_2012_RULE_21_22 = 1212201;
MISRA_C_2012_RULE_21_23 = 1212301;
MISRA_C_2012_RULE_21_24 = 1212401;
MISRA_C_2012_RULE_22_1 = 1220101;
MISRA_C_2012_RULE_22_2 = 1220201;
MISRA_C_2012_RULE_22_3 = 1220301;
Expand All @@ -261,6 +274,11 @@ message Result {
MISRA_C_2012_RULE_22_8 = 1220801;
MISRA_C_2012_RULE_22_9 = 1220901;
MISRA_C_2012_RULE_22_10 = 1221001;
MISRA_C_2012_RULE_23_1 = 1230101;
MISRA_C_2012_RULE_23_2 = 1230201;
MISRA_C_2012_RULE_23_3 = 1230301;
MISRA_C_2012_RULE_23_4 = 1230401;
MISRA_C_2012_RULE_23_5 = 1230501;
// prefix 2 for misra-c-2012 dir
MISRA_C_2012_DIR_4_3_ASM_SHOULD_BE_ISOLATED = 2040301;
MISRA_C_2012_DIR_4_3_ASM_SHOULD_BE_ENCAPSULATED = 2040302;
Expand Down
4 changes: 2 additions & 2 deletions autosar/rule_A0_1_3/libtooling/rule_A0_1_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ int rule_A0_1_3(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& option_parser = expected_parser.get();
std::vector<std::string> path_list = option_parser.getSourcePathList();
if (path_list.size() != 1) {
llvm::errs() << "The number of filepath is not equal to 1";
errs() << "The number of filepath is not equal to 1";
return 1;
}
ClangTool tool(option_parser.getCompilations(),
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A0_1_4/libtooling/rule_A0_1_4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rule_A0_1_4(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = expected_parser.get();
Expand Down
4 changes: 2 additions & 2 deletions autosar/rule_A0_1_5/libtooling/rule_A0_1_5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ int rule_A0_1_5(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& option_parser = expected_parser.get();
std::vector<std::string> path_list = option_parser.getSourcePathList();
if (path_list.size() != 1) {
llvm::errs() << "The number of filepath is not equal to 1";
errs() << "The number of filepath is not equal to 1";
return 1;
}
ClangTool tool(option_parser.getCompilations(),
Expand Down
11 changes: 5 additions & 6 deletions autosar/rule_A0_4_2/libtooling/checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ namespace autosar {
namespace rule_A0_4_2 {
namespace libtooling {

class Callback : public ast_matchers::MatchFinder::MatchCallback {
class Callback : public MatchFinder::MatchCallback {
public:
void Init(analyzer::proto::ResultsList* results_list,
ast_matchers::MatchFinder* finder) {
void Init(ResultsList* results_list, MatchFinder* finder) {
results_list_ = results_list;
finder->addMatcher(
functionDecl(unless(isExpansionInSystemHeader())).bind("func"), this);
Expand All @@ -58,7 +57,7 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
this);
}

void run(const ast_matchers::MatchFinder::MatchResult& result) override {
void run(const MatchFinder::MatchResult& result) override {
auto checkTypeAndReport = [&result, this](const QualType type,
const Decl* decl) {
if (!type->isSpecificBuiltinType(BuiltinType::LongDouble)) return;
Expand All @@ -78,10 +77,10 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
}

private:
analyzer::proto::ResultsList* results_list_;
ResultsList* results_list_;
};

void Checker::Init(analyzer::proto::ResultsList* results_list) {
void Checker::Init(ResultsList* results_list) {
results_list_ = results_list;
callback_ = new Callback;
callback_->Init(results_list, &finder_);
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A0_4_2/libtooling/rule_A0_4_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int rule_A0_4_2(int argc, char** argv) {
libtooling_argc, &const_argv[argc - libtooling_argc],
ns_libtooling_checker);
if (!ep) {
llvm::errs() << ep.takeError();
errs() << ep.takeError();
return 1;
}
tooling::CommonOptionsParser& op = ep.get();
Expand Down
20 changes: 9 additions & 11 deletions autosar/rule_A10_1_1/libtooling/checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ using std::string;

namespace {

void ReportError(const std::string& path, int line_number,
void ReportError(const string& path, int line_number,
ResultsList* results_list) {
std::string error_message =
string error_message =
"Class shall not be derived from more than one base class which is not an interface class.";
misra::proto_util::AddResultToResultsList(results_list, path, line_number,
error_message);
AddResultToResultsList(results_list, path, line_number, error_message);
LOG(INFO) << absl::StrFormat("%s, path: %s, line: %d", error_message, path,
line_number);
}
Expand All @@ -56,18 +55,17 @@ bool isInterfaceClass(const CXXRecordDecl* decl) {
return true;
}

class Callback : public ast_matchers::MatchFinder::MatchCallback {
class Callback : public MatchFinder::MatchCallback {
public:
void Init(analyzer::proto::ResultsList* results_list,
ast_matchers::MatchFinder* finder) {
void Init(ResultsList* results_list, MatchFinder* finder) {
results_list_ = results_list;

finder->addMatcher(
tagDecl(isClass(), unless(isExpansionInSystemHeader())).bind("decl"),
this);
}

void run(const ast_matchers::MatchFinder::MatchResult& result) {
void run(const MatchFinder::MatchResult& result) {
const CXXRecordDecl* decl =
cast<CXXRecordDecl>(result.Nodes.getNodeAs<TagDecl>("decl"));
if (!decl->hasDefinition()) {
Expand All @@ -83,7 +81,7 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
if (!isInterfaceClass(rd)) {
cnt++;
if (cnt > 1) {
std::string path =
string path =
misra::libtooling_utils::GetFilename(decl, result.SourceManager);
int line_number =
misra::libtooling_utils::GetLine(decl, result.SourceManager);
Expand All @@ -95,10 +93,10 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
}

private:
analyzer::proto::ResultsList* results_list_;
ResultsList* results_list_;
};

void Checker::Init(analyzer::proto::ResultsList* result_list) {
void Checker::Init(ResultsList* result_list) {
results_list_ = result_list;
callback_ = new Callback;
callback_->Init(results_list_, &finder_);
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_1_1/libtooling/rule_A10_1_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int rule_A10_1_1(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& options_parser = expected_parser.get();
Expand Down
20 changes: 9 additions & 11 deletions autosar/rule_A10_2_1/libtooling/checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ using std::string;

namespace {

void ReportError(const std::string& path, int line_number,
void ReportError(const string& path, int line_number,
ResultsList* results_list) {
std::string error_message =
string error_message =
"Non-virtual public or protected member functions shall not be redefined in derived classes.";
misra::proto_util::AddResultToResultsList(results_list, path, line_number,
error_message);
AddResultToResultsList(results_list, path, line_number, error_message);
LOG(INFO) << absl::StrFormat("%s, path: %s, line: %d", error_message, path,
line_number);
}
Expand All @@ -62,10 +61,9 @@ bool isRedefined(const CXXMethodDecl* a, const CXXMethodDecl* b) {
}
}

class Callback : public ast_matchers::MatchFinder::MatchCallback {
class Callback : public MatchFinder::MatchCallback {
public:
void Init(analyzer::proto::ResultsList* results_list,
ast_matchers::MatchFinder* finder) {
void Init(ResultsList* results_list, MatchFinder* finder) {
results_list_ = results_list;

finder->addMatcher(
Expand All @@ -78,7 +76,7 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
this);
}

void run(const ast_matchers::MatchFinder::MatchResult& result) {
void run(const MatchFinder::MatchResult& result) {
const CXXMethodDecl* decl = result.Nodes.getNodeAs<CXXMethodDecl>("decl");
const CXXRecordDecl* rd = result.Nodes.getNodeAs<CXXRecordDecl>("rd");

Expand All @@ -91,7 +89,7 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
if (method->isUserProvided() && isRedefined(method, decl)) {
if (!method->isVirtual() &&
method->getAccess() != clang::AS_private) {
std::string path = misra::libtooling_utils::GetFilename(
string path = misra::libtooling_utils::GetFilename(
decl, result.SourceManager);
int line_number =
misra::libtooling_utils::GetLine(decl, result.SourceManager);
Expand All @@ -106,10 +104,10 @@ class Callback : public ast_matchers::MatchFinder::MatchCallback {
}

private:
analyzer::proto::ResultsList* results_list_;
ResultsList* results_list_;
};

void Checker::Init(analyzer::proto::ResultsList* result_list) {
void Checker::Init(ResultsList* result_list) {
results_list_ = result_list;
callback_ = new Callback;
callback_->Init(results_list_, &finder_);
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_2_1/libtooling/rule_A10_2_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int rule_A10_2_1(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& options_parser = expected_parser.get();
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_3_1/libtooling/rule_A10_3_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rule_A10_3_1(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = expected_parser.get();
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_3_2/libtooling/rule_A10_3_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rule_A10_3_2(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = expected_parser.get();
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_3_3/libtooling/rule_A10_3_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rule_A10_3_3(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = expected_parser.get();
Expand Down
2 changes: 1 addition & 1 deletion autosar/rule_A10_3_5/libtooling/rule_A10_3_5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rule_A10_3_5(int argc, char** argv) {
ns_libtooling_checker);
gflags::ParseCommandLineFlags(&gflag_argc, &argv, false);
if (!expected_parser) {
llvm::errs() << expected_parser.takeError();
errs() << expected_parser.takeError();
return 1;
}
CommonOptionsParser& OptionsParser = expected_parser.get();
Expand Down
Loading

0 comments on commit 9694d41

Please sign in to comment.