Skip to content

transpile: Fix translation failures exposed by SQLite - #2001

Merged
thedataking merged 5 commits into
masterfrom
perl/sqlite-transpiler-fixes
Sep 10, 2026
Merged

transpile: Fix translation failures exposed by SQLite#2001
thedataking merged 5 commits into
masterfrom
perl/sqlite-transpiler-fixes

Conversation

@thedataking

@thedataking thedataking commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Fix five translation failures exposed by SQLite's individual source files:

  • Register the main file before emitting the exporter's file table. Comment-only translation units otherwise introduce an unknown file ID and panic during include-path lookup.
  • Construct integer-derived opaque pointers through c_void pointers. Exposed-provenance constructors require sized pointees, while opaque extern types are unsized.
  • Specify the destination type when reading function pointers with va_arg. Enclosing casts can prevent Rust from inferring it.
  • Lower atomic function pointer operations through raw pointers in both Clang atomic expressions and legacy __sync_* builtins. Rust's atomic intrinsics reject the Option<fn> representation of nullable C callbacks.
  • Initialize _Atomic storage through its underlying value type. Default initialization otherwise fails for local atomic declarations, including explicitly initialized ones.

@thedataking
thedataking force-pushed the perl/sqlite-transpiler-fixes branch from f409fa9 to c6c1988 Compare September 8, 2026 02:33
@thedataking
thedataking marked this pull request as ready for review September 8, 2026 03:24
@thedataking
thedataking requested a review from ahomescu September 8, 2026 03:25
@thedataking
thedataking force-pushed the perl/sqlite-transpiler-fixes branch from c6c1988 to 2ec4c4d Compare September 8, 2026 03:34
Comment thread c2rust-transpile/src/translator/pointers.rs Outdated
Comment thread c2rust-transpile/src/translator/variadic.rs
Comment thread c2rust-transpile/src/translator/atomics.rs Outdated
@thedataking

Copy link
Copy Markdown
Contributor Author

Updated to use c_void and added a generated-code example explaining the varargs type-inference fix. The atomic
conversion is now shared with the legacy __sync_* paths, with coverage for exchange, compare-and-swap, and
release, including null callbacks.

Translation units without declarations have no AST nodes to register
their main file. Exporting comments then introduces a file ID absent
from the file table, causing include-path lookup to panic.

Register the main file before serializing the table so comments always
refer to an exported file.
…ointers

Exposed-provenance constructors require Sized pointees, but forward
declarations become unsized extern types. Construct a c_void pointer
first, then cast to the opaque pointer type while preserving its
constness. This allows integer sentinel values and runtime addresses
to initialize opaque pointers in both supported Rust editions.
… va_arg

An enclosing cast can prevent Rust from inferring the destination of
the transmute used for nullable function pointers. Pass the converted
C type explicitly so va_arg results can be assigned through function
pointer typedefs and struct fields.
Rust atomic intrinsics reject Option<fn>, the representation of nullable
C function pointers. Convert atomic operands to raw pointers and
convert results back to their function pointer type.

Share the conversion between Clang atomic expressions and legacy __sync
builtins. Preserve null callbacks, exchange and compare-exchange results,
and the expected value written back after a failed comparison. Lock
release stores a null raw pointer instead of an integer zero.
Default initialization does not handle CTypeKind::Atomic, so local
_Atomic declarations fail to translate even when they have an explicit
initializer. Delegate to the underlying value type to produce the
initializer for the atomic storage.
@thedataking
thedataking force-pushed the perl/sqlite-transpiler-fixes branch from ea90ce8 to b72bfb8 Compare September 10, 2026 06:30
@thedataking
thedataking merged commit f1fe26c into master Sep 10, 2026
11 checks passed
@thedataking
thedataking deleted the perl/sqlite-transpiler-fixes branch September 10, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants