`freeing without malloc i32* %1` error if class contains `vector`
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 22
Description
In following example, when I compile I get the following message in my terminal
```
freeing without malloc i32* %1
```
But the code still compiles and produces the binary artifacts. It only happens if the `Point` class contains a `vector` member. Though the Enzyme Explorer shows it as compilation error (https://fwd.gymni.ch/YG0k2b).
Is it ignore-able warning or underlying bug etc?
```Cpp
#include
#include
int enzyme_dup;
int enzyme_const;
int enzyme_out;
class Point{
public:
double x;
double y;
std::vector a;
Point(double x, double y): x(x), y(y){
a.push_back(0);
}
Point():x(0.0),y(0.0){}
};
class BaseClass{
public:
double x2, y2;
BaseClass(double x2, double y2):x2(x2), y2(y2) {}
void operation(double x1, double y1, Point &P2){
Point P1 = Point(x1,y1);
this->actual_operation(P1, P2);
}
virtual void actual_operation(Point &P1, Point &P2) = 0;
};
class ImplementedClass: public BaseClass{
public:
ImplementedClass(double x, double y):BaseClass(x, y){}
void actual_operation(Point &P1, Point &P2){
P2.x = P1.x + this->x2;
P2.y = P1.y + this->y2;
}
};
void wrapper(double x, double y, Point &p1, ImplementedClass &IC1){
IC1.operation(x, y, p1);
}
void __enzyme_autodiff(void(*)(double, double, Point&, ImplementedClass &), int, double, double, int, double, double, int, Point &, Point &, int, ImplementedClass&);
int main()
{
double x = 2.0;
double y= 3.0;
Point p1(0.,0.);
ImplementedClass ic1(3.,4.);
ic1.operation(x, y, p1);
wrapper(x, y, p1, ic1);
std::cout << p1.x << " " << p1.y << std::endl;
double d_x = 2.0;
double d_y= 3.0;
Point d_p1(0.,0.);
__enzyme_autodiff(wrapper, enzyme_dup, x, d_x, enzyme_dup, y, d_y, enzyme_dup, p1, d_p1, enzyme_const, ic1);
return 0;
}
```
Compiled as
> clang++ main.cpp -Xclang -load -Xclang /opt/enzyme/enzyme/build/Enzyme/ClangEnzyme-12.so -O3 -o a.out
Another related bug is that Enzyme segfaults if I use `.reserve(n)` function of vector. But it only happens in my full codebase, and I am unable to reproduce in simple example yet. If that offers any clue.
Contributor guide
Assessment
This issue has not been assessed yet.