immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.92k stars 230 forks source link

Could not find `CStmtId(40104)` in `TypedAstContext` #336

Open pgillet opened 3 years ago

pgillet commented 3 years ago

Hi,

I try to transpile GraphBLAS. I successfully compiled and installed the project following its guidelines and it produced the required compile_commands.json.

However, invoking c2rust transpile compile_commands.json with RUST_BACKTRACE=full gives the following output that I can't really understand:

At the beginning:

error: unknown argument: '-fcx-limited-range'
warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: optimization flag '-fexcess-precision=fast' is not supported [-Wignored-optimization-argument]
...

And at the very end:

...
thread 'main' panicked at 'Could not find CStmtId(40104) in TypedAstContext', /home/pascal/.cargo/registry/src/github.com-1ecc6299db9ec823/c2rust-transpile-0.15.1/src/c_ast/mod.rs:861:21
stack backtrace:
   0:     0x55cc8ebc24c4 - backtrace::backtrace::libunwind::trace::ha87d00c939e2881d
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1:     0x55cc8ebc24c4 - backtrace::backtrace::trace_unsynchronized::h016b03a8ea0b9a9f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2:     0x55cc8ebc24c4 - std::sys_common::backtrace::_print_fmt::hfe96d08d6bc9b78a
                               at src/libstd/sys_common/backtrace.rs:84
   3:     0x55cc8ebc24c4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3b3abdb96a6d8973
                               at src/libstd/sys_common/backtrace.rs:61
   4:     0x55cc8ebe7d4c - core::fmt::write::h3f73f70567a9d69c
                               at src/libcore/fmt/mod.rs:1024
   5:     0x55cc8ebbf117 - std::io::Write::write_fmt::h7a7dac6f9b6edbe2
                               at src/libstd/io/mod.rs:1428
   6:     0x55cc8ebc46ae - std::sys_common::backtrace::_print::h26e7c67b8d6504c8
                               at src/libstd/sys_common/backtrace.rs:65
   7:     0x55cc8ebc46ae - std::sys_common::backtrace::print::h8adaf32a939cdd8b
                               at src/libstd/sys_common/backtrace.rs:50
   8:     0x55cc8ebc46ae - std::panicking::default_hook::{{closure}}::h8bd3295a48e2a09e
                               at src/libstd/panicking.rs:193
   9:     0x55cc8ebc43a1 - std::panicking::default_hook::hc4fa4a1f08ea09c8
                               at src/libstd/panicking.rs:210
  10:     0x55cc8ebc4d2b - std::panicking::rust_panic_with_hook::h21d3a9bbac50e22b
                               at src/libstd/panicking.rs:471
  11:     0x55cc8ebc48de - rust_begin_unwind
                               at src/libstd/panicking.rs:375
  12:     0x55cc8ebc4820 - std::panicking::begin_panic_fmt::ha7f413ce5baf5d18
                               at src/libstd/panicking.rs:326
  13:     0x55cc8e7863a0 - c2rust_transpile::c_ast::TypedAstContext::get_src_loc::h34b71249bbd2a975
  14:     0x55cc8e6bc1c2 - <c2rust_transpile::translator::comments::CommentLocator as c2rust_transpile::c_ast::iterators::NodeVisitor>::pre::h06cc908e635ff1d9
  15:     0x55cc8e6a73ed - c2rust_transpile::c_ast::iterators::NodeVisitor::visit_tree::hefbad52db131e9a6
  16:     0x55cc8e6f843e - c2rust_transpile::translator::comments::<impl c2rust_transpile::translator::Translation>::locate_comments::h6503b58a85e3584e
  17:     0x55cc8e789a03 - c2rust_transpile::translator::translate::{{closure}}::h430ac01c78c88f8f
  18:     0x55cc8e765964 - scoped_tls::ScopedKey<T>::set::hdc06ae9f358b3472
  19:     0x55cc8e69f38d - syntax::with_globals::haf12cfde16ad7368
  20:     0x55cc8e715876 - c2rust_transpile::translator::translate::h9615bcca2f6d923d
  21:     0x55cc8e765acc - scoped_tls::ScopedKey<T>::set::he0656e8b94588338
  22:     0x55cc8e69f466 - syntax::with_globals::hb499d87b7506079e
  23:     0x55cc8e68b5b5 - c2rust_transpile::transpile_single::he906018beb68214f
  24:     0x55cc8e8668ee - <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h88e1d2a625c3d67b
  25:     0x55cc8e68771a - c2rust_transpile::transpile::hf89d315abc4b7775
  26:     0x55cc8e673b05 - c2rust_transpile::main::h91ac53b3a0b8ec6f
  27:     0x55cc8e6703a3 - std::rt::lang_start::{{closure}}::h8ee053c17c1781c8
  28:     0x55cc8ebc4773 - std::rt::lang_start_internal::{{closure}}::haa7f5f572844d294
                               at src/libstd/rt.rs:52
  29:     0x55cc8ebc4773 - std::panicking::try::do_call::h342bf71ccf436f13
                               at src/libstd/panicking.rs:292
  30:     0x55cc8ebcbaca - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:78
  31:     0x55cc8ebc5280 - std::panicking::try::h0fafde8de6610233
                               at src/libstd/panicking.rs:270
  32:     0x55cc8ebc5280 - std::panic::catch_unwind::h77cbab1217857414
                               at src/libstd/panic.rs:394
  33:     0x55cc8ebc5280 - std::rt::lang_start_internal::h94ca1c3e541ce4b6
                               at src/libstd/rt.rs:51
  34:     0x55cc8e674082 - main
  35:     0x7fa8c091e0b3 - __libc_start_main
  36:     0x55cc8e66f11e - _start
  37:                0x0 - <unknown>

I'in using C2Rust 0.15.1.

Thank you very much if you can provide any hint on how I could work around this issue!

seanlinsley commented 2 years ago

I'm currently trying to transpile a project that includes xxHash and am running into the same error using the latest version of c2rust (39be293c50235b169a76e38203865c4e60378235).

git clone https://github.com/Cyan4973/xxHash
cd xxHash
intercept-build make
../c2rust/target/debug/c2rust transpile compile_commands.json
warning: Missing child 187651756699440 of node AstNode { tag: TagCompoundStmt, children: [Some(187651756695832), Some(187651756696168), Some(187651756696320), Some(187651756697368), Some(187651756697608), Some(187651756697728), Some(187651756699440), Some(187651756700056), Some(187651756700256)], loc: SrcSpan { fileid: 1, begin_line: 3995, begin_column: 5, end_line: 4034, end_column: 5 }, type_id: None, rvalue: LValue, macro_expansions: [], macro_expansion_text: Some("XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX)"), extras: [] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /home/ubuntu/xxHash/xxhash.h:3995:5
 [-Wclang-ast]
thread 'main' panicked at 'Could not find CStmtId(5811) in TypedAstContext', c2rust-transpile/src/c_ast/mod.rs:240:38

There are many similar warnings so I just included the first one for brevity. Two blocks of code are causing the warnings:

seanlinsley commented 2 years ago

I see #229 is also related to xxHash. I'm running c2rust on macOS from inside an Ubuntu VM. I'm able to transpile lz4 without -fno-blocks, so some versions of xxHash seem to work.

OWissett commented 1 year ago

I am having the same issue when trying to transpile a codebase which uses OpenMP, using gcc-9.4.0 on linux.

Once I removed OpenMP, it transpiles.

CearX commented 1 month ago

在尝试在 linux 上使用 gcc-9.4.0 转译使用 的代码库时,我遇到了同样的问题。OpenMP

一旦我删除,它就会转译。OpenMP

我尝试删除OpenMP就能转译了,非常感谢