Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid miscompilation of variadic functions
- Loading branch information
1 parent
aab6eed
commit 0c8cebb
Showing
9 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
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,13 @@ | ||
#pragma once | ||
|
||
#include "mull/Filters/FunctionFilter.h" | ||
|
||
namespace mull { | ||
|
||
class VariadicFunctionFilter : public FunctionFilter { | ||
public: | ||
bool shouldSkip(llvm::Function *function) override; | ||
std::string name() override; | ||
~VariadicFunctionFilter() override = default; | ||
}; | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "mull/Filters/VariadicFunctionFilter.h" | ||
#include <llvm/IR/Function.h> | ||
|
||
using namespace mull; | ||
|
||
bool VariadicFunctionFilter::shouldSkip(llvm::Function *function) { | ||
return function->isVarArg(); | ||
} | ||
|
||
std::string VariadicFunctionFilter::name() { | ||
return "variadic functions"; | ||
} |
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,56 @@ | ||
// clang-format off | ||
#include <stdarg.h> | ||
|
||
extern unsigned long strlen(const char *s); | ||
extern char *strcpy(char * dst, const char * src); | ||
extern int printf(const char *, ...); | ||
extern void abort(); | ||
|
||
static int a = 10; | ||
static int b = 32; | ||
static int c = 0; | ||
|
||
void fill_in(const char *what, int n, ...) { | ||
c = a + b; | ||
va_list args; | ||
va_start(args, n); | ||
for (int i = 0; i < n; ++i) { | ||
char *buf = va_arg(args, char *); | ||
int w_len = strlen(what); | ||
int b_len = strlen(buf); | ||
if (w_len > b_len) { | ||
printf("CRASHING\n"); | ||
abort(); | ||
} | ||
strcpy(buf, what); | ||
buf[i] = '_'; | ||
buf[b_len] = '\0'; | ||
} | ||
va_end(args); | ||
} | ||
|
||
int main() { | ||
char b1[16] = "initialize"; | ||
char b2[16] = "initialize"; | ||
char b3[16] = "initialize"; | ||
char b4[16] = "initialize"; | ||
fill_in("test", 4, b1, b2, b3, b4); | ||
printf("%s\n", b1); | ||
printf("%s\n", b2); | ||
printf("%s\n", b3); | ||
printf("%s\n", b4); | ||
printf("%d\n", c); | ||
return 0; | ||
} | ||
|
||
// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe | ||
// RUN: %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines | ||
// CHECK:_est | ||
// CHECK-NEXT:t_st | ||
// CHECK-NEXT:te_t | ||
// CHECK-NEXT:tes_ | ||
// CHECK-NEXT:42 | ||
// CHECK-EMPTY | ||
|
||
// RUN: unset TERM; %mull_runner %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK_MUTANT | ||
// CHECK_MUTANT:[info] No mutants found. Mutation score: infinitely high |
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,3 @@ | ||
mutators: | ||
- cxx_add_to_sub | ||
quiet: false |