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

explorer crashes when a choice alternative has the same name as choice itself #1248

Closed
pk19604014 opened this issue May 11, 2022 · 1 comment · Fixed by #1243
Closed

explorer crashes when a choice alternative has the same name as choice itself #1248

pk19604014 opened this issue May 11, 2022 · 1 comment · Fixed by #1243
Assignees

Comments

@pk19604014
Copy link
Contributor

$ cat /tmp/crash.carbon
package Test impl;

choice Ch {
Opt(Ch)
}

fn Main() -> i32 {
return 0;
}

$ bazel run explorer:explorer /tmp/crash.carbon

/usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/optional:911: _LIBCPP_ASSERT 'this->has_value()' failed. optional operator* called on a disengaged value
Please report issues to https://github.com/carbon-language/carbon-lang/issues and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/local/google/home/pk19604014/.cache/bazel/_bazel_pk19604014/4adf340e1e81154d644e53e952b3b0b8/execroot/carbon/bazel-out/k8-fastbuild/bin/explorer/explorer /tmp/crash.carbon
#0 0x00005614343d9beb backtrace /tmp/llvm-20220302-9880-1faggz0/llvm-project-13.0.1.src/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:4202:13
#1 0x00005614346f241b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:13
#2 0x00005614346f26bb PrintStackTraceSignalHandler(void*) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
#3 0x00005614346ecd18 llvm::sys::RunSignalHandlers() /proc/self/cwd/external/llvm-project/llvm/lib/Support/Signals.cpp:98:18
#4 0x00005614346f3c6e SignalHandler(int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
#5 0x00007f7955a1d200 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12200)
#6 0x00007f79556c68a1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:50:1
#7 0x00007f79556b0546 abort ./stdlib/abort.c:81:7
#8 0x000056143486d27f (/usr/local/google/home/pk19604014/.cache/bazel/_bazel_pk19604014/4adf340e1e81154d644e53e952b3b0b8/execroot/carbon/bazel-out/k8-fastbuild/bin/explorer/explorer+0x90927f)
#9 0x000056143447fa32 std::__1::optional<Carbon::Value const*>::operator*() const & /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/optional:911:9
#10 0x00005614344865fd static_type /proc/self/cwd/./explorer/ast/declaration.h:57:54
#11 0x00005614344865fd operator() /proc/self/cwd/./explorer/ast/static_scope.h:89:45
#12 0x00005614344865fd decltype(static_castCarbon::ChoiceDeclaration(fp)(static_cast<Carbon::AstNode const&>(fp0))) std::__1::__invoke<Carbon::ValueNodeView::ValueNodeView<Carbon::ChoiceDeclaration, void>(Carbon::ChoiceDeclaration const*)::'lambda1'(Carbon::AstNode const&)&, Carbon::AstNode const&>(Carbon::ChoiceDeclaration&&, Carbon::AstNode const&) /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/type_traits:3918:1
#13 0x00005614344865d9 std::__1::__function::__alloc_func<Carbon::ValueNodeView::ValueNodeView<Carbon::ChoiceDeclaration, void>(Carbon::ChoiceDeclaration const*)::'lambda1'(Carbon::AstNode const&), std::__1::allocator<Carbon::ValueNodeView::ValueNodeView<Carbon::ChoiceDeclaration, void>(Carbon::ChoiceDeclaration const*)::'lambda1'(Carbon::AstNode const&)>, Carbon::Value const& (Carbon::AstNode const&)>::operator()(Carbon::AstNode const&) /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/__functional/function.h:171:9
#14 0x000056143448645d std::__1::__function::__func<Carbon::ValueNodeView::ValueNodeView<Carbon::ChoiceDeclaration, void>(Carbon::ChoiceDeclaration const*)::'lambda1'(Carbon::AstNode const&), std::__1::allocator<Carbon::ValueNodeView::ValueNodeView<Carbon::ChoiceDeclaration, void>(Carbon::ChoiceDeclaration const*)::'lambda1'(Carbon::AstNode const&)>, Carbon::Value const& (Carbon::AstNode const&)>::operator()(Carbon::AstNode const&) /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/__functional/function.h:345:5
#15 0x00005614344e81d6 std::__1::__function::__value_func<Carbon::Value const& (Carbon::AstNode const&)>::operator()(Carbon::AstNode const&) const /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/__functional/function.h:498:9
#16 0x00005614344be552 Carbon::ValueNodeView::static_type() const /proc/self/cwd/./explorer/ast/static_scope.h:116:46
#17 0x00005614344aff75 Carbon::TypeChecker::TypeCheckExp(Carbon::Expression*, Carbon::ImplScope const&) /proc/self/cwd/explorer/interpreter/type_checker.cpp:919:13
#18 0x00005614344ae898 Carbon::TypeChecker::TypeCheckExp(Carbon::Expression*, Carbon::ImplScope const&) /proc/self/cwd/explorer/interpreter/type_checker.cpp:0:9
#19 0x00005614344e4c7f Carbon::TypeChecker::DeclareChoiceDeclaration(Carbon::ChoiceDeclaration*, Carbon::ImplScope const&) /proc/self/cwd/explorer/interpreter/type_checker.cpp:0:5
#20 0x00005614344d9f91 index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:788:12
#21 0x00005614344d9f91 index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1438:59
#22 0x00005614344d9f91 __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1464:14
#23 0x00005614344d9f91 holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1470:10
#24 0x00005614344d9f91 ok /proc/self/cwd/./common/error.h:61:36
#25 0x00005614344d9f91 Carbon::TypeChecker::DeclareDeclaration(Carbon::Declaration*, Carbon::ImplScope&) /proc/self/cwd/explorer/interpreter/type_checker.cpp:2174:7
#26 0x00005614344e63fb index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:788:12
#27 0x00005614344e63fb index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1438:59
#28 0x00005614344e63fb __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1464:14
#29 0x00005614344e63fb holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1470:10
#30 0x00005614344e63fb ok /proc/self/cwd/./common/error.h:61:36
#31 0x00005614344e63fb Carbon::TypeChecker::TypeCheck(Carbon::AST&) /proc/self/cwd/explorer/interpreter/type_checker.cpp:2078:5
#32 0x00005614344615cb ~__tree /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/__tree:1791:11
#33 0x00005614344615cb ~set /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/set:619:5
#34 0x00005614344615cb ~TypeChecker /proc/self/cwd/./explorer/interpreter/type_checker.h:21:7
#35 0x00005614344615cb Carbon::ExecProgram(Carbon::Arena*, Carbon::AST, std::__1::optionalllvm::raw_ostream*) /proc/self/cwd/explorer/interpreter/exec_program.cpp:46:3
#36 0x0000561434453d50 ~AST /proc/self/cwd/./explorer/ast/ast.h:17:8
#37 0x0000561434453d50 Carbon::Main(llvm::StringRef, int, char**) /proc/self/cwd/explorer/main.cpp:78:3
#38 0x0000561434452d5c index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:788:12
#39 0x0000561434452d5c index /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1438:59
#40 0x0000561434452d5c __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1464:14
#41 0x0000561434452d5c holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/local/google/home/pk19604014/.linuxbrew/Cellar/llvm/13.0.1_1/bin/../include/c++/v1/variant:1470:10
#42 0x0000561434452d5c ok /proc/self/cwd/./common/error.h:61:36
#43 0x0000561434452d5c Carbon::ExplorerMain(llvm::StringRef, int, char**) /proc/self/cwd/explorer/main.cpp:88:69
#44 0x00005614344521d1 main /proc/self/cwd/explorer/main_bin.cpp:0:10
#45 0x00007f79556b17fd __libc_start_main ./csu/../csu/libc-start.c:332:16
#46 0x00005614343a0fca _start (/usr/local/google/home/pk19604014/.cache/bazel/_bazel_pk19604014/4adf340e1e81154d644e53e952b3b0b8/execroot/carbon/bazel-out/k8-fastbuild/bin/explorer/explorer+0x43cfca)

@pk19604014
Copy link
Contributor Author

Inner choice alternative name gets resolved to the outer ChoiceDeclaration, and during type checking, the logic tries to access the static type of the alternative expression, which is not set, as choice declaration is assigned a static type after alternatives finish type-checking (unlike classes).

Possible workaround is to fail name lookup for the inner choice alternative name by adding Choice name to the scope after processing choice's alternative.

@pk19604014 pk19604014 self-assigned this May 11, 2022
jonmeow pushed a commit that referenced this issue May 11, 2022
…hoice name (#1243)

Fixes #1248

Changed resolve names logic to add choice name to name resolution after choice's alternatives are added.
zygoloid pushed a commit that referenced this issue May 26, 2022
For issues #1248, #1249, #1257, #1263
Before the samples were only recorded as fuzzer corpus files which are less 'durable'
chandlerc pushed a commit that referenced this issue Jun 28, 2022
…hoice name (#1243)

Fixes #1248

Changed resolve names logic to add choice name to name resolution after choice's alternatives are added.
chandlerc pushed a commit that referenced this issue Jun 28, 2022
For issues #1248, #1249, #1257, #1263
Before the samples were only recorded as fuzzer corpus files which are less 'durable'
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

Successfully merging a pull request may close this issue.

1 participant