-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Insert a space when mutating an expression directly after a macro expansion. Fixes #239.
- Loading branch information
Showing
7 changed files
with
286 additions
and
0 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,6 @@ | ||
#define BEGIN x = | ||
|
||
int main() { | ||
int x, y; | ||
BEGIN(y); | ||
} |
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,59 @@ | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#ifdef _MSC_VER | ||
#define thread_local __declspec(thread) | ||
#elif __APPLE__ | ||
#define thread_local __thread | ||
#else | ||
#include <threads.h> | ||
#endif | ||
|
||
static thread_local int __dredd_some_mutation_enabled = 1; | ||
static int __dredd_enabled_mutation(int local_mutation_id) { | ||
static thread_local int initialized = 0; | ||
static thread_local uint64_t enabled_bitset[1]; | ||
if (!initialized) { | ||
int some_mutation_enabled = 0; | ||
const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); | ||
if (dredd_environment_variable) { | ||
char* temp = malloc(strlen(dredd_environment_variable) + 1); | ||
strcpy(temp, dredd_environment_variable); | ||
char* token; | ||
token = strtok(temp, ","); | ||
while(token) { | ||
int value = atoi(token); | ||
int local_value = value - 0; | ||
if (local_value >= 0 && local_value < 7) { | ||
enabled_bitset[local_value / 64] |= (1 << (local_value % 64)); | ||
some_mutation_enabled = 1; | ||
} | ||
token = strtok(NULL, ","); | ||
} | ||
free(temp); | ||
} | ||
initialized = 1; | ||
__dredd_some_mutation_enabled = some_mutation_enabled; | ||
} | ||
return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); | ||
} | ||
|
||
static int __dredd_replace_expr_int(int arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return arg; | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return !(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return ~(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 2)) return -(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 3)) return 0; | ||
if (__dredd_enabled_mutation(local_mutation_id + 4)) return 1; | ||
if (__dredd_enabled_mutation(local_mutation_id + 5)) return -1; | ||
return arg; | ||
} | ||
|
||
#define BEGIN x = | ||
|
||
int main() { | ||
int x, y; | ||
if (!__dredd_enabled_mutation(6)) { BEGIN __dredd_replace_expr_int((y), 0); } | ||
} |
66 changes: 66 additions & 0 deletions
66
test/single_file/space_needed_after_macro.c.noopt.expected
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,66 @@ | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#ifdef _MSC_VER | ||
#define thread_local __declspec(thread) | ||
#elif __APPLE__ | ||
#define thread_local __thread | ||
#else | ||
#include <threads.h> | ||
#endif | ||
|
||
static thread_local int __dredd_some_mutation_enabled = 1; | ||
static int __dredd_enabled_mutation(int local_mutation_id) { | ||
static thread_local int initialized = 0; | ||
static thread_local uint64_t enabled_bitset[1]; | ||
if (!initialized) { | ||
int some_mutation_enabled = 0; | ||
const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); | ||
if (dredd_environment_variable) { | ||
char* temp = malloc(strlen(dredd_environment_variable) + 1); | ||
strcpy(temp, dredd_environment_variable); | ||
char* token; | ||
token = strtok(temp, ","); | ||
while(token) { | ||
int value = atoi(token); | ||
int local_value = value - 0; | ||
if (local_value >= 0 && local_value < 15) { | ||
enabled_bitset[local_value / 64] |= (1 << (local_value % 64)); | ||
some_mutation_enabled = 1; | ||
} | ||
token = strtok(NULL, ","); | ||
} | ||
free(temp); | ||
} | ||
initialized = 1; | ||
__dredd_some_mutation_enabled = some_mutation_enabled; | ||
} | ||
return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); | ||
} | ||
|
||
static int __dredd_replace_expr_int_lvalue(int* arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return (*arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return ++((*arg)); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return --((*arg)); | ||
return (*arg); | ||
} | ||
|
||
static int __dredd_replace_expr_int(int arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return arg; | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return !(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return ~(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 2)) return -(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 3)) return 0; | ||
if (__dredd_enabled_mutation(local_mutation_id + 4)) return 1; | ||
if (__dredd_enabled_mutation(local_mutation_id + 5)) return -1; | ||
return arg; | ||
} | ||
|
||
#define BEGIN x = | ||
|
||
int main() { | ||
int x, y; | ||
if (!__dredd_enabled_mutation(14)) { __dredd_replace_expr_int(BEGIN __dredd_replace_expr_int( __dredd_replace_expr_int_lvalue(&((y)), 0), 2), 8); } | ||
} |
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,6 @@ | ||
#define BEGIN_ x = | ||
|
||
int main() { | ||
int x, y; | ||
BEGIN_(y); | ||
} |
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,59 @@ | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#ifdef _MSC_VER | ||
#define thread_local __declspec(thread) | ||
#elif __APPLE__ | ||
#define thread_local __thread | ||
#else | ||
#include <threads.h> | ||
#endif | ||
|
||
static thread_local int __dredd_some_mutation_enabled = 1; | ||
static int __dredd_enabled_mutation(int local_mutation_id) { | ||
static thread_local int initialized = 0; | ||
static thread_local uint64_t enabled_bitset[1]; | ||
if (!initialized) { | ||
int some_mutation_enabled = 0; | ||
const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); | ||
if (dredd_environment_variable) { | ||
char* temp = malloc(strlen(dredd_environment_variable) + 1); | ||
strcpy(temp, dredd_environment_variable); | ||
char* token; | ||
token = strtok(temp, ","); | ||
while(token) { | ||
int value = atoi(token); | ||
int local_value = value - 0; | ||
if (local_value >= 0 && local_value < 7) { | ||
enabled_bitset[local_value / 64] |= (1 << (local_value % 64)); | ||
some_mutation_enabled = 1; | ||
} | ||
token = strtok(NULL, ","); | ||
} | ||
free(temp); | ||
} | ||
initialized = 1; | ||
__dredd_some_mutation_enabled = some_mutation_enabled; | ||
} | ||
return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); | ||
} | ||
|
||
static int __dredd_replace_expr_int(int arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return arg; | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return !(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return ~(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 2)) return -(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 3)) return 0; | ||
if (__dredd_enabled_mutation(local_mutation_id + 4)) return 1; | ||
if (__dredd_enabled_mutation(local_mutation_id + 5)) return -1; | ||
return arg; | ||
} | ||
|
||
#define BEGIN_ x = | ||
|
||
int main() { | ||
int x, y; | ||
if (!__dredd_enabled_mutation(6)) { BEGIN_ __dredd_replace_expr_int((y), 0); } | ||
} |
66 changes: 66 additions & 0 deletions
66
test/single_file/space_needed_after_macro2.c.noopt.expected
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,66 @@ | ||
#include <inttypes.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#ifdef _MSC_VER | ||
#define thread_local __declspec(thread) | ||
#elif __APPLE__ | ||
#define thread_local __thread | ||
#else | ||
#include <threads.h> | ||
#endif | ||
|
||
static thread_local int __dredd_some_mutation_enabled = 1; | ||
static int __dredd_enabled_mutation(int local_mutation_id) { | ||
static thread_local int initialized = 0; | ||
static thread_local uint64_t enabled_bitset[1]; | ||
if (!initialized) { | ||
int some_mutation_enabled = 0; | ||
const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); | ||
if (dredd_environment_variable) { | ||
char* temp = malloc(strlen(dredd_environment_variable) + 1); | ||
strcpy(temp, dredd_environment_variable); | ||
char* token; | ||
token = strtok(temp, ","); | ||
while(token) { | ||
int value = atoi(token); | ||
int local_value = value - 0; | ||
if (local_value >= 0 && local_value < 15) { | ||
enabled_bitset[local_value / 64] |= (1 << (local_value % 64)); | ||
some_mutation_enabled = 1; | ||
} | ||
token = strtok(NULL, ","); | ||
} | ||
free(temp); | ||
} | ||
initialized = 1; | ||
__dredd_some_mutation_enabled = some_mutation_enabled; | ||
} | ||
return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); | ||
} | ||
|
||
static int __dredd_replace_expr_int_lvalue(int* arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return (*arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return ++((*arg)); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return --((*arg)); | ||
return (*arg); | ||
} | ||
|
||
static int __dredd_replace_expr_int(int arg, int local_mutation_id) { | ||
if (!__dredd_some_mutation_enabled) return arg; | ||
if (__dredd_enabled_mutation(local_mutation_id + 0)) return !(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 1)) return ~(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 2)) return -(arg); | ||
if (__dredd_enabled_mutation(local_mutation_id + 3)) return 0; | ||
if (__dredd_enabled_mutation(local_mutation_id + 4)) return 1; | ||
if (__dredd_enabled_mutation(local_mutation_id + 5)) return -1; | ||
return arg; | ||
} | ||
|
||
#define BEGIN_ x = | ||
|
||
int main() { | ||
int x, y; | ||
if (!__dredd_enabled_mutation(14)) { __dredd_replace_expr_int(BEGIN_ __dredd_replace_expr_int( __dredd_replace_expr_int_lvalue(&((y)), 0), 2), 8); } | ||
} |