Skip to content

Segfault for calling random.random() twice #2544

Open
@certik

Description

@certik

The following code:

from lpython import i32, f64
import random

def test_seed():
    i: i32
    a: f64 = random.random()
    for i in range(10):
        b: f64 = random.random()

test_seed()

gives:

$ lpython b.py 
Traceback (most recent call last):
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 1872
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 786
    r1 = LCompilers::LPython::python_ast_to_asr(al, lm, nullptr, *ast, diagnostics, compiler_options,
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 8016
    auto res2 = body_visitor(al, lm, *ast_m, diagnostics, unit, main_module, module_name,
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7952
    BodyVisitor b(al, lm, unit, diagnostics, main_module, module_name, ast_overload, allow_implicit_casting);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4732
    visit_stmt(*x.m_body[i]);
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1883
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1751
    case stmtType::FunctionDef: { v.visit_FunctionDef((const FunctionDef_t &)x); return; }
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4833
    handle_fn(x, *f);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4809
    transform_stmts(body, x.n_body, x.m_body);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4686
    this->visit_stmt(*m_body[i]);
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1883
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1758
    case stmtType::AnnAssign: { v.visit_AnnAssign((const AnnAssign_t &)x); return; }
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 5534
    transform_stmts(body, x.n_body, x.m_body);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4686
    this->visit_stmt(*m_body[i]);
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1883
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1757
    case stmtType::AugAssign: { v.visit_AugAssign((const AugAssign_t &)x); return; }
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 4904
    visit_AnnAssignUtil(x, var_name, init_expr);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 2831
    this->visit_expr(*x.m_value);
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1910
    void visit_expr(const expr_t &b) { visit_expr_t(b, self()); }
  File "/Users/ondrej/repos/lpython/src/lpython/python_ast.h", line 1799
    case exprType::Compare: { v.visit_Compare((const Compare_t &)x); return; }
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7418
    handle_attribute(at, args, x.base.base.loc);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 7267
    tmp = make_call_helper(al, st, current_scope, args, call_name, loc);
  File "/Users/ondrej/repos/lpython/src/lpython/semantics/python_ast_to_asr.cpp", line 1086
    s = ASRUtils::symbol_get_past_external(s);
  Binary file "/usr/lib/system/libsystem_platform.dylib", local address: 0x1803244e3
Segfault: Signal SIGSEGV (segmentation fault) received

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions