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 has lifetime(?) bug with String associated constants #1439

Closed
zygoloid opened this issue Jul 20, 2022 · 1 comment · Fixed by #1548
Closed

explorer has lifetime(?) bug with String associated constants #1439

zygoloid opened this issue Jul 20, 2022 · 1 comment · Fixed by #1548
Labels
explorer Action items related to Carbon explorer code good first issue Possibly a good first issue for newcomers

Comments

@zygoloid
Copy link
Contributor

package Testcase api;

interface HasName {
    let Name:! String;
}

external impl i32 as HasName where .Name == "i32" {}
external impl String as HasName where .Name == "String" {}

fn Main() -> i32 {
    Print(String.(HasName.Name));
    return 0;
}

https://carbon.compiler-explorer.com/z/esP9c8zsn
prints:

����V
result: 0

(A different garbage string each run.) Looks like a use-after-free of a string to me.

@zygoloid zygoloid added explorer Action items related to Carbon explorer code good first issue Possibly a good first issue for newcomers labels Jul 20, 2022
@tkadur
Copy link
Contributor

tkadur commented Jul 21, 2022

When I try to run explorer locally on that code I get the following compiler crash. Not sure why it doesn't match Compiler Explorer's behavior.

Error message
explorer: external/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = Carbon::StringValue, From = Carbon::Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Please report issues to https://github.com/carbon-language/carbon-lang/issues and include the crash backtrace.
Stack dump:
0.	Program arguments: bazel_bin/explorer/explorer explorer/testdata/string/associated_constant.carbon
 #0 0x0000557204711e1b backtrace (bazel_bin/explorer/explorer+0x4d7e1b)
 #1 0x0000557204aa2feb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:13
 #2 0x0000557204aa328b PrintStackTraceSignalHandler(void*) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #3 0x0000557204a9d8e8 llvm::sys::RunSignalHandlers() /proc/self/cwd/external/llvm-project/llvm/lib/Support/Signals.cpp:104:18
 #4 0x0000557204aa3f0e SignalHandler(int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #5 0x00007f153593e200 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12200)
 #6 0x00007f15355e68a1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:50:1
 #7 0x00007f15355d0546 abort ./stdlib/abort.c:81:7
 #8 0x00007f15355d042f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #9 0x00007f15355d042f _nl_load_domain ./intl/loadmsgcat.c:970:34
#10 0x00007f15355df222 (/lib/x86_64-linux-gnu/libc.so.6+0x31222)
#11 0x00005572048c42ec decltype(auto) llvm::cast<Carbon::StringValue, Carbon::Value>(Carbon::Value const&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/Support/Casting.h:566:3
#12 0x00005572048b945a Carbon::Interpreter::StepExp() /proc/self/cwd/explorer/interpreter/interpreter.cpp:1154:47
#13 0x00005572048ac3e3 index /usr/lib/llvm-13/bin/../include/c++/v1/variant:788:12
#14 0x00005572048ac3e3 index /usr/lib/llvm-13/bin/../include/c++/v1/variant:1438:59
#15 0x00005572048ac3e3 __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/lib/llvm-13/bin/../include/c++/v1/variant:1464:14
#16 0x00005572048ac3e3 holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/lib/llvm-13/bin/../include/c++/v1/variant:1470:10
#17 0x00005572048ac3e3 ok /proc/self/cwd/./common/error.h:62:36
#18 0x00005572048ac3e3 Carbon::Interpreter::Step() /proc/self/cwd/explorer/interpreter/interpreter.cpp:1646:7
#19 0x00005572048d1875 Carbon::Interpreter::RunAllSteps(std::__1::unique_ptr<Carbon::Action, std::__1::default_delete<Carbon::Action> >) /proc/self/cwd/explorer/interpreter/interpreter.cpp:0:5
#20 0x00005572048d2680 ~unique_ptr /usr/lib/llvm-13/bin/../include/c++/v1/__memory/unique_ptr.h:272:19
#21 0x00005572048d2680 Carbon::InterpProgram(Carbon::AST const&, Carbon::Arena*, std::__1::optional<llvm::raw_ostream*>) /proc/self/cwd/explorer/interpreter/interpreter.cpp:1697:3
#22 0x000055720479a6e8 Carbon::ExecProgram(Carbon::Arena*, Carbon::AST, std::__1::optional<llvm::raw_ostream*>) /proc/self/cwd/explorer/interpreter/exec_program.cpp:56:1
#23 0x000055720478c857 ~AST /proc/self/cwd/./explorer/ast/ast.h:17:8
#24 0x000055720478c857 Carbon::Main(llvm::StringRef, int, char**) /proc/self/cwd/explorer/main.cpp:78:3
#25 0x000055720478b85c index /usr/lib/llvm-13/bin/../include/c++/v1/variant:788:12
#26 0x000055720478b85c index /usr/lib/llvm-13/bin/../include/c++/v1/variant:1438:59
#27 0x000055720478b85c __holds_alternative<1UL, Carbon::Error, Carbon::Success> /usr/lib/llvm-13/bin/../include/c++/v1/variant:1464:14
#28 0x000055720478b85c holds_alternative<Carbon::Success, Carbon::Error, Carbon::Success> /usr/lib/llvm-13/bin/../include/c++/v1/variant:1470:10
#29 0x000055720478b85c ok /proc/self/cwd/./common/error.h:62:36
#30 0x000055720478b85c Carbon::ExplorerMain(llvm::StringRef, int, char**) /proc/self/cwd/explorer/main.cpp:91:69
#31 0x000055720478acd1 main /proc/self/cwd/explorer/main_bin.cpp:0:10
#32 0x00007f15355d17fd __libc_start_main ./csu/../csu/libc-start.c:332:16
#33 0x00005572046d91fa _start (bazel_bin/explorer/explorer+0x49f1fa)
zsh: IOT instruction  bazel run //explorer explorer/testdata/string/associated_constant.carbon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorer Action items related to Carbon explorer code good first issue Possibly a good first issue for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants