Fix initialized memory error reported by Valgrind. Disable 2 tests that produce memory leaks due to a bug in g++.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-09-10 13:50:35 -07:00
parent fae6c29237
commit 6fe86ffefd
3 changed files with 31 additions and 3 deletions

View file

@ -514,7 +514,24 @@ class pp_fn {
if (m_implicit_args) { if (m_implicit_args) {
unsigned r = 0; unsigned r = 0;
for (unsigned i = 0; i < num_args(m_app) - 1; i++) { for (unsigned i = 0; i < num_args(m_app) - 1; i++) {
if (!(*m_implicit_args)[i]) // Remark: we need the test i >= m_implicit_args because the application
// m_app may contain more arguments than the declaration of m_f.
// Example:
// m_f was declared as
// Pi {A : Type} (a : A) : A
// Thus m_implicit_args has size 2, and contains {true, false}
// indicating that the first argument is implicit.
// Then, the actuall application is:
// f (Int -> Int) g 10
// Assuming g has type Int -> Int.
// This application is fine and has type Int.
// We should not print the argument (Int -> Int) since it is
// implicit.
// We should view the application above as:
// (f (Int -> Int) g) 10
// So, the arguments at position >= m_implicit_args->size()
// are explicit by default.
if (i >= m_implicit_args->size() || !(*m_implicit_args)[i])
r++; r++;
} }
return r; return r;
@ -528,7 +545,8 @@ class pp_fn {
if (m_implicit_args) { if (m_implicit_args) {
unsigned n = num_args(m_app); unsigned n = num_args(m_app);
for (unsigned j = 1; j < n; j++) { for (unsigned j = 1; j < n; j++) {
if (!(*m_implicit_args)[j-1]) { // See comment in get_num_args()
if (j - 1 >= m_implicit_args->size() || !(*m_implicit_args)[j-1]) {
// explicit argument found // explicit argument found
if (i == 0) if (i == 0)
return arg(m_app, j); return arg(m_app, j);

View file

@ -82,6 +82,10 @@ static void tst5() {
} }
static void tst6() { static void tst6() {
#if 0
// Disabling test to avoid memory leak error message produced by Valgrind.
// The memory leak is due to a bug in the g++ compiler.
// Soonho reported the problem. Gcc team said this a known problem, and will be fixed
std::cout << "tst6\n"; std::cout << "tst6\n";
std::cout << mk_int_add_fn().raw() << "\n"; std::cout << mk_int_add_fn().raw() << "\n";
std::cout << mk_int_add_fn().raw() << "\n"; std::cout << mk_int_add_fn().raw() << "\n";
@ -93,6 +97,7 @@ static void tst6() {
t2.join(); t2.join();
#endif #endif
std::cout << mk_int_add_fn().raw() << "\n"; std::cout << mk_int_add_fn().raw() << "\n";
#endif
} }
int main() { int main() {

View file

@ -10,7 +10,7 @@ Author: Leonardo de Moura
#include <mutex> #include <mutex>
#include <vector> #include <vector>
static void foo() { void foo() {
static thread_local std::vector<int> v(1024); static thread_local std::vector<int> v(1024);
if (v.size() != 1024) { if (v.size() != 1024) {
std::cerr << "Error\n"; std::cerr << "Error\n";
@ -19,11 +19,16 @@ static void foo() {
} }
static void tst1() { static void tst1() {
#if 0
// Disabling test to avoid memory leak error message produced by Valgrind.
// The memory leak is due to a bug in the g++ compiler.
// Soonho reported the problem. Gcc team said this a known problem, and will be fixed
unsigned n = 5; unsigned n = 5;
for (unsigned i = 0; i < n; i++) { for (unsigned i = 0; i < n; i++) {
std::thread t([](){ foo(); }); std::thread t([](){ foo(); });
t.join(); t.join();
} }
#endif
} }
int main() { int main() {