Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent GMP values in lambdas from outliving their stack frame #168

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,27 @@ DoConstantFolding::cast(const IR::Constant* node, unsigned base, const IR::Type_
}

const IR::Node* DoConstantFolding::postorder(IR::Add* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a + b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a + b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Sub* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a - b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a - b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Mul* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a * b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a * b; });
}

const IR::Node* DoConstantFolding::postorder(IR::BXor* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a ^ b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a ^ b; });
}

const IR::Node* DoConstantFolding::postorder(IR::BAnd* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a & b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a & b; });
}

const IR::Node* DoConstantFolding::postorder(IR::BOr* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a | b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a | b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Equ* e) {
Expand All @@ -193,23 +193,23 @@ const IR::Node* DoConstantFolding::postorder(IR::Neq* e) {
}

const IR::Node* DoConstantFolding::postorder(IR::Lss* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a < b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a < b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Grt* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a > b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a > b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Leq* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a <= b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a <= b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Geq* e) {
return binary(e, [](mpz_class a, mpz_class b) { return a >= b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a >= b; });
}

const IR::Node* DoConstantFolding::postorder(IR::Div* e) {
return binary(e, [e](mpz_class a, mpz_class b)->mpz_class {
return binary(e, [e](mpz_class a, mpz_class b) -> mpz_class {
if (sgn(a) < 0 || sgn(b) < 0) {
::error("%1%: Division is not defined for negative numbers", e);
return 0;
Expand All @@ -223,7 +223,7 @@ const IR::Node* DoConstantFolding::postorder(IR::Div* e) {
}

const IR::Node* DoConstantFolding::postorder(IR::Mod* e) {
return binary(e, [e](mpz_class a, mpz_class b)->mpz_class {
return binary(e, [e](mpz_class a, mpz_class b) -> mpz_class {
if (sgn(a) < 0 || sgn(b) < 0) {
::error("%1%: Modulo is not defined for negative numbers", e);
return 0;
Expand Down Expand Up @@ -265,9 +265,9 @@ DoConstantFolding::compare(const IR::Operation_Binary* e) {
}

if (eqTest)
return binary(e, [](mpz_class a, mpz_class b) { return a == b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a == b; });
else
return binary(e, [](mpz_class a, mpz_class b) { return a != b; });
return binary(e, [](mpz_class a, mpz_class b) -> mpz_class { return a != b; });
}

const IR::Node*
Expand Down