Skip to content

Commit

Permalink
Merge branch 'master' of github.com:csmith-project/csmith
Browse files Browse the repository at this point in the history
  • Loading branch information
regehr committed Oct 24, 2011
2 parents 85df3bc + c56d5b9 commit 2f6a8ed
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/ArrayVariable.h
Expand Up @@ -80,6 +80,7 @@ class ArrayVariable : public Variable
void output_init(std::ostream &out, const Expression* init, const vector<const Variable*>& cvs, int indent) const;
void output_addr_checks(std::ostream &out, const Variable* var, string field_name, int indent) const;
void add_init_value(const Expression* e) { init_values.push_back(e);}
const vector<const Expression*>& get_init_values(void) const { return init_values;}
string build_initializer_str(const vector<string>& init_strings) const;
string build_init_recursive(size_t dimen, const vector<string>& init_strings) const;

Expand Down
71 changes: 42 additions & 29 deletions src/Reducer.cpp
Expand Up @@ -71,8 +71,6 @@ Reducer::Reducer(string fname)
rewrite_calls_inside(NULL),
reduce_binaries(false),
output_if_ids(false),
print_value_with_multi_lines(false),
test_command_line_option(false),
monitored_var(NULL),
monitored_func(NULL),
monitored_call_id(""),
Expand Down Expand Up @@ -128,6 +126,22 @@ Reducer::configure(void)
monitored_var = key;
used_vars.push_back(key->get_named_var());
}
// find the line that crashed a compiler
else if (line.find("crc lines") == 0) {
getline(conf, line);
StringUtils::chop(line);
// find the global variables in CRC statements, and mark them as used
vector<string> strs;
StringUtils::split_string(line, strs, "(),[.");
for (size_t i=0; i<strs.size(); i++) {
if (strs[i].find("g_") == 0) {
const Variable* v = VariableSelector::find_var_by_name(strs[i]);
assert(v);
add_variable_to_set(used_vars, v);
}
}
crc_lines = line;
}
else if (line.find("keep variable") == 0) {
getline(conf, line);
StringUtils::chop(line);
Expand All @@ -153,13 +167,6 @@ Reducer::configure(void)
getline(conf, line);
config_active_blks(line);
}
else if (line.find("print checksum with multi-lines") == 0) {
print_value_with_multi_lines = true;
}
else if (line.find("test command line option") == 0) {
test_command_line_option = true;
main_str = "func_1()";
}
else if (line.find("call chain shortcut") == 0) {
getline(conf, line);
config_call_chain_shortcut(line);
Expand Down Expand Up @@ -403,12 +410,12 @@ Reducer::delete_stms_after(const Statement* stm, bool include_parent_blks)

if (begin_delete) {
if (find_required_labels(s, labels)==0 && s != return_stm) {
// don't delete statements that contains add-back blocks (those has 0 count in mao_active_blks)
// don't delete statements that contains add-back blocks (those has 0 count in map_active_blks)
vector<const Block*> blks;
s->get_blocks(blks);
bool must_dump = false;
for (j=0; j<blks.size(); j++) {
if (map_active_blks[blks[j]] == 0) {
if (!is_blk_deleted(blks[j]) && map_active_blks[blks[j]] == 0) {
must_dump = true;
break;
}
Expand Down Expand Up @@ -461,27 +468,33 @@ Reducer::find_local_vars_to_lift(vector<const Variable*>& vars)
void
Reducer::expand_used_vars(void)
{
size_t i;
size_t i, j;
for (i=0; i<used_vars.size(); i++) {
const Variable* v = used_vars[i];
const Expression* init = v->init;
if (init && init->term_type == eVariable) {
const ExpressionVariable* ev = (const ExpressionVariable*)(init);
if (ev->get_indirect_level() < 0) {
string dummy;
const Variable* addr_var = ev->get_var()->get_array(dummy);
// if not an array ...
if (addr_var == 0) {
addr_var = ev->get_var();
}
addr_var = addr_var->get_named_var();
if (!is_var_used(addr_var)) {
bool found = false;
// if find no appropriate variable in used list, use the original variable
if (!found) {
used_vars.push_back(addr_var);
vector<const Expression*> init_values;
if (v->isArray) {
const ArrayVariable* av = dynamic_cast<const ArrayVariable*>(v);
init_values = av->get_init_values();
}
init_values.push_back(v->init);

for (j=0; j<init_values.size(); j++) {
const Expression* init = init_values[j];
if (init && init->term_type == eVariable) {
const ExpressionVariable* ev = (const ExpressionVariable*)(init);
if (ev->get_indirect_level() < 0) {
string dummy;
const Variable* addr_var = ev->get_var()->get_array(dummy);
// if not an array ...
if (addr_var == 0) {
addr_var = ev->get_var();
}
}
// if addr_var is a field, get the container var
addr_var = addr_var->get_named_var();
if (!is_var_used(addr_var)) {
used_vars.push_back(addr_var);
}
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Reducer.h
Expand Up @@ -122,11 +122,10 @@ class Reducer
const Function* rewrite_calls_inside;
bool reduce_binaries;
bool output_if_ids;
bool print_value_with_multi_lines;
bool test_command_line_option;
const Variable* monitored_var;
const Function* monitored_func;
string monitored_call_id;
string crc_lines;

std::map<const Block*, int> map_active_blks;
vector<int> all_blks;
Expand Down
32 changes: 21 additions & 11 deletions src/ReducerOutputMgr.cpp
Expand Up @@ -245,20 +245,25 @@ ReducerOutputMgr::output_main_func(std::ostream& out)
{
size_t i;
const Function* f = reducer->main;
if (!reducer->test_command_line_option && f->param.size() == 0 && (reducer->main_str == "" || reducer->main_str.find("func_")==0)) {
if (f->param.size() == 0 && (reducer->main_str == "" || reducer->main_str.find("func_")==0)) {
out << "int main(void)" << endl;
output_block(f->body, out, 0);
if (reducer->is_blk_deleted(f->body)) {
out << "{" << endl;
if (!reducer->crc_lines.empty()) {
output_tab(out, 1);
out << reducer->crc_lines << endl;
}
output_tab(out, 1);
out << "return 0;" << endl;
out << "}" << endl;
}
else {
output_block(f->body, out, 0);
}
}
else {
output_func(f, out);
// make an artificial main function
if (reducer->test_command_line_option) {
out << endl << "int main(int argc, char* argv[]) {" << endl;
output_tab(out, 1);
out << "if (argc == 2 && strcmp(argv[1], \"1\") == 0) { int i = 1;}" << endl;
} else {
out << endl << "int main(void) {" << endl;
}
out << endl << "int main(void) {" << endl;
output_tab(out, 1);
// break up function call and parameters, and skip parameters that are reduced
vector<string> strs;
Expand Down Expand Up @@ -620,11 +625,16 @@ ReducerOutputMgr::output_reduced_stm(const Statement* stm, std::ostream &out, in
ostringstream oss;
const Variable* key = reducer->monitored_var;
oss << "checksum " << key->get_actual_name() << " = ";
key->output_runtime_value(out, oss.str(), "\\n", indent, reducer->print_value_with_multi_lines);
key->output_runtime_value(out, oss.str(), "\\n", indent, 0);
outputln(out);
}
}
if (stm->func == GetFirstFunction()) {
// output crc lines if they are required
if (!reducer->crc_lines.empty()) {
output_tab(out, indent);
out << reducer->crc_lines;
}
output_tab(out, indent);
out << "return 0;" << endl;
return;
Expand Down

0 comments on commit 2f6a8ed

Please sign in to comment.