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

Assert statements don't properly mark their message arguments as used causing the linker to fail. #1354

Closed
MinekPo1 opened this issue Aug 12, 2024 · 1 comment
Assignees
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Milestone

Comments

@MinekPo1
Copy link

MinekPo1 commented Aug 12, 2024

Minimal example:

import std::io;

fn String foo() {
    return "hello from foo!";
}

// c3c complains about using assert(false), so we need to trick it
fn bool bar() {
    return false;
}

fn void main() {
    io::printn("Hello, World!");
    assert(bar(), "%s", foo());
}

The linker error message is undefined reference to .foo', we can further confirm this is the case by looking at the object file, where we find foo` referenced but undefined:

000000000 V $ct.char
0000000000000000 V $ct.sa$char
0000000000000000 V $ct.String
0000000000000003 r .file
000000000000000b r .func
0000000000000000 r .L.str
0000000000000000 T <module>_fn.bar
                 U <module>_fn.foo
0000000000000010 T <module>_fn.main
00000000000001a0 T main
0000000000000000 r .panic_msg
                 U std.core.builtin.panicf
                 U std.io.File.flush
                 U std.io.File.write
                 U std.io.File.write_byte
                 U std.io.stdout

Tested with c3c 0.6.2, with llvm 17.0.6 targeting x86_64-pc-linux-gnu (TODO: test with a master build)

Not sure if its the correct pass, but in sema_liveness.c I have found one example of a semantic pass not descending into the message arguments, and "liveness" sounds like it looks for dead code, which feels right.

@lerno lerno self-assigned this Aug 12, 2024
@lerno lerno added the Bug Something isn't working label Aug 12, 2024
@lerno lerno added the Fixed Needs Verification Fixed, but needs verification that it works label Aug 12, 2024
@lerno
Copy link
Collaborator

lerno commented Aug 12, 2024

This was indeed sema_liveness. It should now be patched. Please close this when you have verified that it works as intended.

@lerno lerno added this to the 0.6.2 milestone Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Projects
None yet
Development

No branches or pull requests

2 participants