Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from mull-project/junk_detection_replace_call
Junk detection for ReplaceCall mutator
- Loading branch information
Showing
9 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
include/mull/JunkDetection/CXX/Visitors/ReplaceCallVisitor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "InstructionRangeVisitor.h" | ||
#include "VisitorParameters.h" | ||
|
||
#include <clang/AST/RecursiveASTVisitor.h> | ||
|
||
namespace mull { | ||
|
||
class ReplaceCallVisitor | ||
: public clang::RecursiveASTVisitor<ReplaceCallVisitor> { | ||
public: | ||
ReplaceCallVisitor(const VisitorParameters ¶meters); | ||
|
||
bool VisitCallExpr(clang::CallExpr *callExpression); | ||
bool VisitCXXMemberCallExpr(clang::CXXMemberCallExpr *callExpression); | ||
bool VisitCXXOperatorCallExpr(clang::CXXOperatorCallExpr *callExpression); | ||
void handleCallExpr(clang::CallExpr *callExpression); | ||
bool foundMutant(); | ||
|
||
private: | ||
InstructionRangeVisitor visitor; | ||
const clang::ASTContext &astContext; | ||
}; | ||
|
||
} // namespace mull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "mull/JunkDetection/CXX/Visitors/ReplaceCallVisitor.h" | ||
|
||
using namespace mull; | ||
|
||
ReplaceCallVisitor::ReplaceCallVisitor(const VisitorParameters ¶meters) | ||
: visitor(parameters), astContext(parameters.astContext) {} | ||
|
||
bool ReplaceCallVisitor::VisitCallExpr(clang::CallExpr *callExpression) { | ||
handleCallExpr(callExpression); | ||
return true; | ||
} | ||
|
||
bool ReplaceCallVisitor::VisitCXXMemberCallExpr( | ||
clang::CXXMemberCallExpr *callExpression) { | ||
handleCallExpr(callExpression); | ||
return true; | ||
} | ||
|
||
bool ReplaceCallVisitor::VisitCXXOperatorCallExpr( | ||
clang::CXXOperatorCallExpr *callExpression) { | ||
handleCallExpr(callExpression); | ||
return true; | ||
} | ||
|
||
void ReplaceCallVisitor::handleCallExpr(clang::CallExpr *callExpression) { | ||
auto *type = callExpression->getType().getTypePtrOrNull(); | ||
/// Real Type = float, double, long double, integer | ||
if (type && type->isRealType()) { | ||
visitor.visitRangeWithLocation(callExpression->getSourceRange()); | ||
} | ||
} | ||
|
||
bool ReplaceCallVisitor::foundMutant() { return visitor.foundRange(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#define call_wrap(x) x() | ||
|
||
extern "C" int external_function(int a, int b, int c); | ||
extern "C" float external_function_f(float a, float b, float c); | ||
|
||
int sum(int x, int b) { | ||
return x + b; | ||
} | ||
|
||
int bar(); | ||
|
||
int foo() { | ||
int r = sum(5, 8); | ||
int s = bar(); | ||
int q = call_wrap(bar); | ||
int a = external_function(r, s, q); | ||
int b = external_function_f(r, s, q); | ||
|
||
return r + s + q + a + b; | ||
} | ||
|
||
class FooBar { | ||
public: | ||
FooBar(int x) : i(x) {} | ||
|
||
int getValue() { return i; } | ||
int increment() { return i++; } | ||
int decrement() { return i--; } | ||
private: | ||
int i; | ||
}; | ||
|
||
struct Buzz { | ||
int x; | ||
int y; | ||
int z; | ||
int w; | ||
}; | ||
|
||
int bar() { | ||
FooBar fbr(42); | ||
external_function(fbr.increment(), fbr.increment(), fbr.increment()); | ||
|
||
external_function(fbr.getValue(), 0, 0); | ||
|
||
return fbr.decrement(); | ||
} | ||
|
||
void buzz() { | ||
Buzz b; | ||
Buzz a = b; | ||
Buzz c; | ||
c = a; | ||
} |