Skip to content

Stack overflow transpiling #1169

@hfiguiere

Description

@hfiguiere

I'm trying to transpile a single C file to Rust.

It ends with:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

The source file (Github force me to gzip)
dcraw.c.gz

The compile command:

[
  {
    "arguments": [
      "gcc",
      "-c",
      "-I/usr/lib/gcc/x86_64-redhat-linux/14/include",
      "-DNO_JASPER",
      "-DNO_JPEG",
      "-DNO_LCMS",
      "dcraw.c"
    ],
    "directory": "/var/home/hub/source/c2rust",
    "file": "/var/home/hub/source/libopenraw/dcraw/dcraw.c"
  }
]

Runing in gdb I get the following:

#0  0x00005555560383ce in __rust_probestack ()
#1  0x0000555555a3f3ca in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x0, ast=..., comment_store=0x7ffffffea4b8)
    at c2rust-transpile/src/cfg/structures.rs:406
#2  0x0000555555a425cb in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:432
#3  0x0000555555a423f3 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:450
#4  0x0000555555a423f3 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:450
#5  0x0000555555a423f3 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:450
#6  0x0000555555a42c51 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:456

[...]

#362 0x0000555555a42c51 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:456
#363 0x0000555555a42c51 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:456
#364 0x0000555555a42c51 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:456
#365 0x0000555555a42c51 in c2rust_transpile::cfg::structures::StructureState::to_stmt (self=0x7ffffffea4b8, ast=..., 
    comment_store=0x7fffffff94a8) at c2rust-transpile/src/cfg/structures.rs:456
#366 0x0000555555a3ec0e in c2rust_transpile::cfg::structures::structured_cfg (root=..., comment_store=0x7fffffff94a8, 
    current_block=0x555557156710, debug_labels=false, cut_out_trailing_ret=true) at c2rust-transpile/src/cfg/structures.rs:24
#367 0x000055555577779c in c2rust_transpile::translator::Translation::convert_cfg (self=0x7fffffff8e80, name=..., graph=..., store=..., 
    live_in=..., cut_out_trailing_ret=true) at c2rust-transpile/src/translator/mod.rs:2501
#368 0x0000555555a308f2 in c2rust_transpile::translator::{impl#4}::convert_function_body::{closure#0} ()
    at c2rust-transpile/src/translator/mod.rs:2521
#369 0x0000555555a39eca in c2rust_transpile::translator::Translation::with_scope<c2rust_transpile::translator::{impl#4}::convert_function_body::{closure_env#0}, core::result::Result<alloc::vec::Vec<syn::stmt::Stmt, alloc::alloc::Global>, c2rust_transpile::diagnostics::TranslationError>> (self=0x7fffffff8e80, f=...) at c2rust-transpile/src/translator/mod.rs:4805
#370 0x0000555555777b99 in c2rust_transpile::translator::Translation::convert_function_body (self=0x7fffffff8e80, ctx=..., name=..., 
    body_ids=..., ret=...) at c2rust-transpile/src/translator/mod.rs:2519
#371 0x0000555555a2f5ac in c2rust_transpile::translator::{impl#4}::convert_function::{closure#0} ()
    at c2rust-transpile/src/translator/mod.rs:2352
#372 0x0000555555a39c6a in c2rust_transpile::translator::Translation::with_scope<c2rust_transpile::translator::{impl#4}::convert_function::{closure_env#0}, core::result::Result<c2rust_transpile::translator::ConvertedDecl, c2rust_transpile::diagnostics::TranslationError>> (
    self=0x7fffffff8e80, f=...) at c2rust-transpile/src/translator/mod.rs:4805
#373 0x00005555557766a8 in c2rust_transpile::translator::Translation::convert_function (self=0x7fffffff8e80, ctx=..., span=..., 
    is_global=true, is_inline=false, is_main=false, is_variadic=false, is_extern=false, new_name=..., name=..., arguments=..., 
    return_type=..., body=..., attrs=0x55555f4a57d0) at c2rust-transpile/src/translator/mod.rs:2250
#374 0x0000555555775f6c in c2rust_transpile::translator::Translation::convert_decl (self=0x7fffffff8e80, ctx=..., decl_id=...)
    at c2rust-transpile/src/translator/mod.rs:1902
#375 0x00005555557634f3 in c2rust_transpile::translator::translate (ast_context=..., tcfg=0x7fffffffdbe0, main_file=...)
    at c2rust-transpile/src/translator/mod.rs:719
#376 0x0000555555675dac in c2rust_transpile::transpile_single (tcfg=0x7fffffffdbe0, input_path=..., ancestor_path=..., build_dir=..., 
    cc_db=..., extra_clang_args=...) at c2rust-transpile/src/lib.rs:536
#377 0x000055555580033f in c2rust_transpile::transpile::{closure#5} (cmd=0x555556411b00) at c2rust-transpile/src/lib.rs:328
#378 0x00005555558b024e in core::iter::adapters::map::map_fold::{closure#0}<&alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>, core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, (), c2rust_transpile::transpile::{closure_env#5}, core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, alloc::vec::spec_extend::{impl#1}::spec_extend::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::alloc::Global>>> (acc=(), elt=0x555556411b00)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/iter/adapters/map.rs:84
#379 0x00005555558bc445 in core::iter::traits::iterator::Iterator::fold<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, (), core::iter::adapters::map::map_fold::{closure_env#0}<&alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>, core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, (), c2rust_transpile::transpile::{closure_env#5}, core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, alloc::vec::spec_extend::{impl#1}::spec_extend::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::alloc::Global>>>> (self=..., init=(), f=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/iter/traits/iterator.rs:2414
#380 0x00005555558a05d4 in core::iter::adapters::map::{impl#2}::fold<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}, (), core::iter::traits::iterator::Iterator::for_each::call::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, alloc::vec::spec_extend::{impl#1}::spec_extend::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::alloc::Global>>> (self=..., init=(), g=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/iter/adapters/map.rs:124
#381 0x00005555558a651f in core::iter::traits::iterator::Iterator::for_each<core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::vec::spec_extend::{impl#1}::spec_extend::{closure_env#0}<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::alloc::Global>> (self=..., f=...) at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/iter/traits/iterator.rs:831
#382 0x00005555559d3e07 in alloc::vec::spec_extend::{impl#1}::spec_extend<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::alloc::Global> (self=0x7fffffffcaf8, iterator=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/alloc/src/vec/spec_extend.rs:40
#383 0x000055555598da59 in alloc::vec::spec_from_iter_nested::{impl#1}::from_iter<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>> (iterator=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/alloc/src/vec/spec_from_iter_nested.rs:62
#384 0x00005555559d851d in alloc::vec::spec_from_iter::{impl#0}::from_iter<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>> (iterator=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/alloc/src/vec/spec_from_iter.rs:33
#385 0x00005555559cdfa0 in alloc::vec::{impl#18}::from_iter<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::Rc<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>> (iter=...) at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/alloc/src/vec/mod.rs:2648
#386 0x00005555558a5a5d in core::iter::traits::iterator::Iterator::collect<core::iter::adapters::map::Map<core::slice::iter::Iter<alloc::rc::R--Type <RET> for more, q to quit, c to continue without paging--
c<c2rust_transpile::compile_cmds::CompileCmd>>, c2rust_transpile::transpile::{closure_env#5}>, alloc::vec::Vec<core::result::Result<(std::path::PathBuf, alloc::vec::Vec<(&str, alloc::vec::Vec<&str, alloc::alloc::Global>), alloc::alloc::Global>, indexmap::set::IndexSet<c2rust_transpile::ExternCrate, std::collections::hash::map::RandomState>), ()>, alloc::alloc::Global>> (self=...)
    at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/iter/traits/iterator.rs:1836
#387 0x000055555567324a in c2rust_transpile::transpile (tcfg=..., cc_db=..., extra_clang_args=...) at c2rust-transpile/src/lib.rs:325
#388 0x0000555555624ad1 in c2rust_transpile::main () at c2rust/src/bin/c2rust-transpile.rs:259

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions