jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
293 stars 27 forks source link

[ICE] bug in parser: loaded a variable that was not declared #473

Open Byter09 opened 4 years ago

Byter09 commented 4 years ago

Code

union u2 u2a;

unions()
{
    u2a ;
}

Expected behavior

Not really a C expert so I have no clue :)

Backtrace ``` The application panicked (crashed). Message: bug in parser: loaded a variable that was not declared Location: /storage/saltwater/src/ir/expr.rs:417 Run with RUST_BACKTRACE=full to include source snippets. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ⋮ 4 frames hidden ⋮ 5: core::panicking::panic_fmt::h1ac71ad045d55416 at src/libcore/panicking.rs:111 6: core::option::expect_failed::h7baa1c60813ff0e3 at src/libcore/option.rs:1260 7: core::option::Option::expect::haf0fc5ded7f49bbc at /rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/libcore/option.rs:347 8: saltwater::ir::expr::>::load_addr::h96d89eb40825f3f0 at /storage/saltwater/src/ir/expr.rs:417 9: saltwater::ir::expr::>::compile_expr::hdc8bc448035e1104 at /storage/saltwater/src/ir/expr.rs:42 10: saltwater::ir::stmt::>::compile_stmt::h33303ef196213b5a at /storage/saltwater/src/ir/stmt.rs:41 11: saltwater::ir::stmt::>::compile_all::ha6f77f726593b383 at /storage/saltwater/src/ir/stmt.rs:19 12: saltwater::ir::Compiler::compile_func::h06b4843792beea31 at /storage/saltwater/src/ir/mod.rs:354 13: saltwater::ir::compile::h57a6ec8de4266bb2 at /storage/saltwater/src/ir/mod.rs:133 14: saltwater::compile::h450fea7b729b8e55 at /storage/saltwater/src/lib.rs:303 15: swcc::aot_main::hedfb546d31e85013 at src/main.rs:175 16: swcc::real_main::hbda82e0ba7f269af at src/main.rs:164 ```
jyn514 commented 4 years ago
$ run_clang 
union u2 u2a;

unions()
{
    u2a ;
}
<stdin>:3:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
unions()
^
<stdin>:5:5: error: incomplete type 'union u2' where a complete type is required
    u2a ;
    ^
<stdin>:1:7: note: forward declaration of 'union u2'
union u2 u2a;
      ^
<stdin>:5:5: warning: expression result unused [-Wunused-value]
    u2a ;
    ^~~
<stdin>:1:10: error: tentative definition has type 'union u2' that is never completed
union u2 u2a;
         ^
<stdin>:1:7: note: forward declaration of 'union u2'
union u2 u2a;
      ^
2 warnings and 2 errors generated.