Closed anutosh491 closed 7 months ago
The llvm_sym
backend works but I think it should not. So we shall debug it through the C backend
Let's go issue by issue
1) I am not sure if every symbolic variable is declared in the correct scope
// Implementations
void mmrv(void* e, void* x, struct list_CPtr *_lpython_return_variable)
{
int64_t _arg0;
int64_t _arg1;
struct list_CPtr _empty_list;
void* _lcompilers_symbolic_argument_container;
void* _lcompilers_symbolic_argument_container1;
int64_t _stack0;
void* arg0;
void* arg1;
struct list_CPtr empty_list;
void* stack0;
int32_t symbolic_list_index;
_arg0 = 0;
arg0 = NULL;
arg0 = (void*) &_arg0;
basic_new_stack(arg0);
_arg1 = 0;
arg1 = NULL;
arg1 = (void*) &_arg1;
basic_new_stack(arg1);
Looking at this block I can see the scope being used is not really correct. Shouldn't we just be seeing empty_list
being declared in this scope. Talking about arg0
, shouldn't we find it being defined in the second if
block (first elif
block)
if (basic_get_type(e) == 29) {
int64_t _arg0;
void* arg0;
_arg0 = 0;
arg0 = NULL;
arg0 = (void*) &_arg0;
// further operation
2) Freeing out variables.
The reason for the segfault is this in the c code
if (!basic_has_symbol(e, x)) {
list_deepcopy_CPtr(&empty_list, _lpython_return_variable);
basic_free_stack(arg0);
basic_free_stack(arg1);
}
As you can see the arg0
& arg1
variables are being freed even before they can be used in the further if blocks.
Freeing is related to this comment (https://github.com/lcompilers/lpython/issues/2533#issuecomment-1946100684) I think
I can only reproduce this issue when I am on the branch of #2528. In master I don't get this segfault with neither LLVM nor C backends.
This issue arises out of this PR https://github.com/lcompilers/lpython/pull/2528. Consider this minimalistic example