aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser1 <user1@ubuntu>2017-03-30 23:56:27 +0000
committeruser1 <user1@ubuntu>2017-03-30 23:56:27 +0000
commit7baf464754738afff528bd79b741ddec59b8a06a (patch)
tree86cca037a44f6d7322b11c15f930888d5abdaa70
parentsome progress on auto-conversion of arrays (diff)
parentadded safercpp native array detection, now also detects use of pointers point... (diff)
downloadmutator-7baf464754738afff528bd79b741ddec59b8a06a.tar.gz
mutator-7baf464754738afff528bd79b741ddec59b8a06a.zip
Merge branch 'master' of https://github.com/bloodstalker/mutator.git
-rw-r--r--mutator-lvl0.cpp154
-rw-r--r--mutator-lvl0.h2
-rw-r--r--safercpp/makefile5
3 files changed, 148 insertions, 13 deletions
diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp
index cacb098..606dc6e 100644
--- a/mutator-lvl0.cpp
+++ b/mutator-lvl0.cpp
@@ -72,10 +72,18 @@ using namespace clang::driver;
using namespace clang::tooling;
/**********************************************************************************************************************/
/*macros and defs*/
+
+/*@DEVI-disbale debugs info printouts.*/
#define _MUT0_TEST
-#if 1
+#if 0
#undef _MUT0_TEST
#endif
+
+/*@DEVI-disbale all matchers.*/
+#define _MUT0_DIS_MATCHERS
+#if 0
+#undef _MUT0_DIS_MATCHERS
+#endif
/**********************************************************************************************************************/
/*global vars*/
Devi::XMLReport XMLDocOut;
@@ -5774,11 +5782,11 @@ class SFCPPARR01 : public MatchFinder::MatchCallback
JSONDocOUT.JSONAddElement(MR.Context, SL, "SaferCPP01", "Native CPP array declared:");
}
- if (MR.Nodes.getNodeAs<clang::ArraySubscriptExpr>("sfcpparrsubscript") != nullptr)
+ if (MR.Nodes.getNodeAs<clang::CastExpr>("sfcpparrcastexpr") != nullptr)
{
- const ArraySubscriptExpr* ASE = MR.Nodes.getNodeAs<clang::ArraySubscriptExpr>("sfcpparrsubscript");
+ const CastExpr* CS = MR.Nodes.getNodeAs<clang::CastExpr>("sfcpparrcastexpr");
- SourceLocation SL = ASE->getLocStart();
+ SourceLocation SL = CS->getLocStart();
CheckSLValidity(SL);
SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start");
@@ -5803,6 +5811,124 @@ class SFCPPARR01 : public MatchFinder::MatchCallback
Rewriter &Rewrite;
};
/**********************************************************************************************************************/
+/**
+ * @brief The matcher run by SFCPPARR02. This ones does all the real tagging.
+ */
+class SFCPPARR02SUB : public MatchFinder::MatchCallback
+{
+ public:
+ SFCPPARR02SUB (Rewriter &Rewrite) : Rewrite(Rewrite) {}
+
+ virtual void run(const MatchFinder::MatchResult &MR)
+ {
+ if (MR.Nodes.getNodeAs<clang::DeclRefExpr>("sfcpp02sub") != nullptr)
+ {
+ const DeclRefExpr* DRE = MR.Nodes.getNodeAs<clang::DeclRefExpr>("sfcpp02sub");
+
+ SourceManager *const SM = MR.SourceManager;
+
+ SourceLocation SL = DRE->getLocStart();
+ CheckSLValidity(SL);
+ //SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start");
+ SL = SM->getSpellingLoc(SL);
+
+ if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
+ {
+ return void();
+ }
+
+ if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL))
+ {
+ return void();
+ }
+
+ const NamedDecl* ND = DRE->getFoundDecl();
+
+ SourceLocation OriginSL = ND->getLocStart();
+ CheckSLValidity(OriginSL);
+ //OriginSL = Devi::SourceLocationHasMacro(OriginSL, Rewrite, "start");
+ OriginSL = SM->getSpellingLoc(OriginSL);
+
+ StringRef OriginFileName [[maybe_unused]] = SM->getFilename(OriginSL);
+
+#if 0
+ std::cout << "GarbageOut" << ":" << "Origin:" << DRE->getFoundDecl()->getName().str() << std::endl;
+ std::cout << "GarbageOut" << ":" << "Origin:" << ExtOriginFileName.str() << ":" << "Proto:" << OriginFileName.str() << std::endl;
+ std::cout << "GarbageOut" << ":" << "Origin:" << ExtOriginSL.printToString(*SM) << ":" << "Proto:" << OriginSL.printToString(*SM) << std::endl;
+#endif
+
+ if (OriginSL == ExtOriginSL && OriginFileName == ExtOriginFileName)
+ {
+ std::cout << "SaferCPP01" << ":" << "Native Array used - pointer points to an array:" << SL.printToString(*MR.SourceManager) << ":" << DRE->getFoundDecl()->getName().str() << std::endl;
+ }
+
+ XMLDocOut.XMLAddNode(MR.Context, SL, "SaferCPP01", "Native Array used - pointer points to an array:");
+ JSONDocOUT.JSONAddElement(MR.Context, SL, "SaferCPP01", "Native Array used - pointer points to an array:");
+ }
+ }
+
+ void setOriginSourceLocation(SourceLocation inSL)
+ {
+ ExtOriginSL = inSL;
+ }
+
+ void setOriginFileName(StringRef inStrRef)
+ {
+ ExtOriginFileName = inStrRef;
+ }
+
+ private:
+ Rewriter &Rewrite;
+ SourceLocation ExtOriginSL;
+ StringRef ExtOriginFileName;
+};
+/**********************************************************************************************************************/
+/**
+ * @brief MatchCallback for safercpp matching of pointers pointing to arrays.
+ */
+class SFCPPARR02 : public MatchFinder::MatchCallback
+{
+ public:
+ SFCPPARR02 (Rewriter &Rewrite) : Rewrite(Rewrite), SubHandler(Rewrite) {}
+
+ virtual void run(const MatchFinder::MatchResult &MR)
+ {
+ if (MR.Nodes.getNodeAs<clang::DeclRefExpr>("sfcpparrdeep") != nullptr)
+ {
+ const DeclRefExpr* DRE = MR.Nodes.getNodeAs<clang::DeclRefExpr>("sfcpparrdeep");
+
+ ASTContext *const ASTC = MR.Context;
+
+ SourceManager *const SM = MR.SourceManager;
+
+ SourceLocation SL = DRE->getLocStart();
+ CheckSLValidity(SL);
+ SL = SM->getSpellingLoc(SL);
+
+ const NamedDecl* ND = DRE->getFoundDecl();
+
+ StringRef NDName = ND->getName();
+
+ SubHandler.setOriginSourceLocation(SM->getSpellingLoc(ND->getLocStart()));
+ SubHandler.setOriginFileName(SM->getFilename(SM->getSpellingLoc(ND->getLocStart())));
+
+ Matcher.addMatcher(declRefExpr(to(varDecl(hasName(NDName.str())))).bind("sfcpp02sub"), &SubHandler);
+
+ Matcher.matchAST(*ASTC);
+
+#if 0
+ std::cout << "GarbageOutOrigin" << ":" << "GarbageOutOrigin:" << SL.printToString(*MR.SourceManager) << ":" << NDName.str() << std::endl;
+#endif
+ }
+ }
+
+ private:
+ Rewriter &Rewrite;
+ MatchFinder Matcher;
+ SFCPPARR02SUB SubHandler;
+};
+/**********************************************************************************************************************/
+/**********************************************************************************************************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
@@ -7297,22 +7423,18 @@ public:
HandlerForPointer1723(R), HandlerForPointer174(R), HandlerForPointer175(R), HandlerForTypes61(R), HandlerForSU181(R), \
HandlerForMCPTCCSTYLE(R), HandlerForATC101(R), HandlerForIdent51(R), HandlerForDCDF87(R), HandlerForDCDF88(R), HandlerForLangX23(R), \
HandlerForFunction167(R), HandlerForCF143(R), HandlerForExpr1212(R), HandlerForExpr1211(R), HandlerForAtc105(R), HandlerForCSE135(R), \
- HandlerForTypes612(R), HandlerForConst71(R), HandlerForIdent5X(R), HandlerForSFCPPARR01(R) {
+ HandlerForTypes612(R), HandlerForConst71(R), HandlerForIdent5X(R), HandlerForSFCPPARR01(R), HandlerForSFCPPARR02(R) {
-#if 1
- /*forstmts whithout a compound statement.*/
+/*@DEVI-disables all matchers*/
+#if defined(_MUT0_DIS_MATCHERS)
Matcher.addMatcher(forStmt(unless(hasDescendant(compoundStmt()))).bind("mcfor"), &HandlerForCmpless);
- /*whilestmts without a compound statement.*/
Matcher.addMatcher(whileStmt(unless(hasDescendant(compoundStmt()))).bind("mcwhile"), &HandlerWhileCmpless);
- /*else blocks that dont have a compound statemnt.*/
Matcher.addMatcher(ifStmt(allOf(hasElse(unless(ifStmt())), hasElse(unless(compoundStmt())))).bind("mcelse"), &HandlerElseCmpless);
- /*if blocks that dont have a compound statement.*/
Matcher.addMatcher(ifStmt(unless(hasDescendant(compoundStmt()))).bind("mcif"), &HandlerIfCmpless);
- /*if-elseif statements that are missing the else block.*/
Matcher.addMatcher(ifStmt(allOf(hasElse(ifStmt()), unless(hasAncestor(ifStmt())), unless(hasDescendant(ifStmt(hasElse(unless(ifStmt()))))))).bind("mcifelse"), &HandlerForIfElse);
Matcher.addMatcher(switchStmt(hasDescendant(compoundStmt(hasDescendant(switchCase(unless(hasDescendant(breakStmt()))))))).bind("mcswitchbrk"), &HandlerForSwitchBrkLess);
@@ -7561,9 +7683,14 @@ public:
Matcher.addMatcher(enumConstantDecl(hasAncestor(functionDecl().bind("id5funcscope"))).bind("ident5enumconst"), &HandlerForIdent5X);
/*end of matchers for 5.x*/
- Matcher.addMatcher(arraySubscriptExpr().bind("sfcpparrsubscript"), &HandlerForSFCPPARR01);
-
Matcher.addMatcher(varDecl(hasType(arrayType())).bind("sfcpparrdecl"), &HandlerForSFCPPARR01);
+
+ Matcher.addMatcher(implicitCastExpr(hasCastKind(CK_ArrayToPointerDecay)).bind("sfcpparrcastexpr"), &HandlerForSFCPPARR01);
+
+ Matcher.addMatcher(cStyleCastExpr(hasCastKind(CK_ArrayToPointerDecay)).bind("sfcpparrcastexpr"), &HandlerForSFCPPARR01);
+
+ Matcher.addMatcher(declRefExpr(hasAncestor(binaryOperator(allOf(hasLHS(declRefExpr().bind("sfcpparrdeep")), hasRHS(hasDescendant(implicitCastExpr(hasCastKind(CK_ArrayToPointerDecay))))\
+ , hasOperatorName("="))))), &HandlerForSFCPPARR02);
#endif
}
@@ -7642,6 +7769,7 @@ private:
MCConst71 HandlerForConst71;
MCIdent5x HandlerForIdent5X;
SFCPPARR01 HandlerForSFCPPARR01;
+ SFCPPARR02 HandlerForSFCPPARR02;
MatchFinder Matcher;
};
/**********************************************************************************************************************/
diff --git a/mutator-lvl0.h b/mutator-lvl0.h
index b79656a..20b26db 100644
--- a/mutator-lvl0.h
+++ b/mutator-lvl0.h
@@ -325,6 +325,8 @@ std::multimap<std::string,std::string> MC1EquivalencyMap = {
{"127","20.12"}
};
+std::pair<std::string, bool> Mutator0RuleChecks;
+
std::multimap<std::string, std::string> MC3EquivalencyMap;
std::unordered_map<std::string, std::string> SaferCPPEquivalencyMap;
diff --git a/safercpp/makefile b/safercpp/makefile
index cba8d9e..cd5a0b8 100644
--- a/safercpp/makefile
+++ b/safercpp/makefile
@@ -3,7 +3,12 @@
include ../macros.mk
#######################################VARS####################################
+CXX_FLAGS+=-frtti
SFCPP01=safercpp-arr
+
+ifeq ($(shell $(LLVM_CONF) --has-rtti), NO)
+$(error your llvm-config says you dont have rtti. you cant build safercpparr without rtti support.)
+endif
######################################RULES####################################
.DEFAULT: all