c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Fatal error: 'stddef.h' file not found

Open djc opened this issue 1 year ago • 11 comments

I tried to transpile cronie. After finally getting c2rust to compile on my Gentoo box (with llvm-17.0.6 installed) and generating compile_commands.json via intercept-build, this is the output I got:

enrai cronie $ ../c2rust/target/release/c2rust transpile compile_commands.json
In file included from anacron/lock.c:29:
/usr/include/stdio.h:33:10: fatal error: 'stddef.h' file not found
   33 | #include <stddef.h>
      |          ^~~~~~~~~~
1 error generated.
Error while processing /home/djc/src/cronie/anacron/lock.c.
Transpiling lock.c
warning: Missing child 93960771518624 of node AstNode { tag: TagCallExpr, children: [Some(93960771518528), Some(93960771518560), Some(93960771518592), Some(93960771518624)], loc: SrcSpan { fileid: 11, begin_line: 41, begin_column: 10, end_line: 41, end_column: 40 }, type_id: Some(93960770786800), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /usr/include/bits/stdio.h:41:10
 [-Wclang-ast]
warning: Missing child 93960772464328 of node AstNode { tag: TagCallExpr, children: [Some(93960772464328), Some(93960772464416), Some(93960772464464), Some(93960772464496)], loc: SrcSpan { fileid: 60, begin_line: 89, begin_column: 9, end_line: 89, end_column: 44 }, type_id: Some(93960770786800), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /home/djc/src/cronie/anacron/lock.c:89:9
 [-Wclang-ast]
warning: Missing child 93960772486248 of node AstNode { tag: TagCallExpr, children: [Some(93960772486248), Some(93960772486336), Some(93960772486384), Some(93960772486416)], loc: SrcSpan { fileid: 6
0, begin_line: 204, begin_column: 9, end_line: 204, end_column: 41 }, type_id: Some(93960770786800), rvalue: RValue, macro_expansions: [], macro_expansion_text: None, extras: [] }
Exported Clang AST was invalid. Check warnings above for unimplemented features.
--> /home/djc/src/cronie/anacron/lock.c:204:9
 [-Wclang-ast]
thread 'main' panicked at 'Type conversion not implemented for TagTypeUnknown expecting 3', c2rust-transpile/src/c_ast/conversion.rs:827:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm a little confused that the process continues after the fatal error concerning stddef.h (and, indeed, why clang can't find that file at this point -- I have one in /usr/lib/clang/17/include/stddef.h). Is there something I could do for TagTypeUnknown expecting 3?

djc avatar Apr 10 '24 12:04 djc

As far as I can tell, this is the problem fixed by commit f3b5623b75127e38ba685faa06ee714dc2904ffb. Make sure your version of c2rust includes that commit (which is newer than the latest release, so you'll have to build from git).

fw-immunant avatar Apr 10 '24 14:04 fw-immunant

I built from 0e732f66e63902c4f8467fac51b9cfe93d458116, which should include that change, right?

djc avatar Apr 10 '24 14:04 djc

0e732f6 does include that change. You can double-check the version you have built with c2rust --version and you can see where the transpiler is looking for stddef.h with strace (you'll have to remove the generated .rs files and run the transpiler afresh):

strace -f -e open,openat,openat2 $CARGO_TARGET_DIR/release/c2rust transpile compile_commands.json

fw-immunant avatar Apr 10 '24 15:04 fw-immunant

The version is as expected. strace output:

[pid 13068] openat(AT_FDCWD, "./stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 13068] openat(AT_FDCWD, "/usr/local/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 13068] openat(AT_FDCWD, "/usr/include/stddef.h", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
In file included from anacron/lock.c:29:
/usr/include/stdio.h:33:10: fatal error: 'stddef.h' file not found
   33 | #include <stddef.h>
      |          ^~~~~~~~~~

djc avatar Apr 10 '24 15:04 djc