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

[Help wanted] Evaluating optional argument to not None gives segmentation fault #3950

Open
kraudy opened this issue Jan 16, 2025 · 1 comment

Comments

@kraudy
Copy link

kraudy commented Jan 16, 2025

Issue description

I have a class that needs an optional argument. When evaluating to None, it gives an error. If evaluating to None gives an error, how am i supposed to evaluate it? But also, i may be doing something wrong.

struct Value:
    var data: UnsafePointer[Float32]
    var _prev3 : List[UnsafePointer[Value]]

    fn __init__(out self, data: Float32,
                        _children2: Optional[List[UnsafePointer[Value]]] = None
                        :
        
        self.data = UnsafePointer[Scalar[DType.float32]].alloc(1)
        self.data.store(data)

        if _children2 is not None:
            self._prev3 = UnsafePointer[Value].alloc(len(_children2.value()))

            for i in range(len(_children2.value())):
                self._prev3[i] = _children2.value()[i]
        else:
            self._prev3 = UnsafePointer[Value].alloc(0)

Steps to reproduce

Bash output

[42727:42727:20250115,205605.282809:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[42727:42727:20250115,205605.282897:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.      Program arguments: mojo engine.mojo
#0 0x00005568f231a6bb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
#1 0x00005568f2318619 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
#2 0x00005568f231ad3d SignalHandler(int) Signals.cpp:0:0
#3 0x00007f5c68f6c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f5c645146ba KGEN_CompilerRT_AsyncRT_CreateRuntime (/home/kraudy/Mojo/mojo-learn/.magic/envs/default/lib/libKGENCompilerRTShared.so+0x146ba)
#5 0x00007ffd8e3f0848 
mojo crashed!
Please file a bug report.
Segmentation fault

Debug output

3
loc(" -> !kgen.none>>":1:2): error: expected non-function type
loc("union<struct<() memoryOnly>, struct<(pointer<none>, index, index) memoryOnly>>, scalar<ui8>)>":1:1): error: expected non-function type
loc(" memoryOnly>, struct<(pointer<none>, index, index) memoryOnly>>":1:2): error: expected non-function type
src/tcmalloc.cc:302] Attempt to free invalid pointer 0x7ffff7c1c5ac 
error: libc.so.6 0x002032e6: DW_TAG_member '__padding' refers to type 0x00000000002032f3 which extends beyond the bounds of 0x002032ce
error: libc.so.6 0x00202b98: DW_TAG_member 'unwind_exception_align' refers to type 0x0000000000202ba6 which extends beyond the bounds of 0x00202b89
error: libc.so.6 0x00202f86: DW_TAG_member 'pad' refers to type 0x0000000000202f9f which extends beyond the bounds of 0x00202f7d
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0.	Program arguments: /home/kraudy/.vscode-server/data/User/globalStorage/modular-mojotools.vscode-mojo/magic-data-home/envs/max/bin/mojo run --no-optimization --debug-level full /home/kraudy/Mojo/mojo-grad/mojograd/engine.mojo
 #0 0x000055555ac996bb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
 #1 0x000055555ac97619 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
 #2 0x000055555ac99d3d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007ffff7907520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007ffff795b9fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x00007ffff795b9fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x00007ffff795b9fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x00007ffff7907476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007ffff78ed7f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x00007ffff7df513b tcmalloc::Log(tcmalloc::LogMode, char const*, int, tcmalloc::LogItem, tcmalloc::LogItem, tcmalloc::LogItem, tcmalloc::LogItem) internal_logging.cc:0:0
#10 0x00007ffff7def89a (anonymous namespace)::InvalidFree(void*) tcmalloc.cc:0:0
#11 0x00007fff840165bb 
mojo crashed!
Please file a bug report.
Process 42859 exited with status = 6 (0x00000006) 
@kraudy kraudy added the dev-console tag for all issues related to dev-console frontend label Jan 16, 2025
@JoeLoser JoeLoser removed the dev-console tag for all issues related to dev-console frontend label Jan 16, 2025
@zyx-billy
Copy link
Contributor

Hi, can you provide a minimal repro for this? That way we can see how the function's called and repro it on our side. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants