Skip to content

std.libc spells C strings *const i8; on an unsigned-char target c_char is u8 (§16.1, #2176) #2585

Closed

Description

@ehartford

§16.1 / #2176: c_char is the target's alias, u8 on AArch64 Linux and wasm. lib/std/libc.w and lib/std/string.w declare C strings as *const i8 / *mut i8 (strlen(s: *const i8), ...), and lib/std/zip.w, collections.w, build.w carry the spelling. On a signed-char host the two are one type; on AArch64 Linux a *const c_char (what c_import and the migrator now spell, after the fix for the linux-aarch64 seed leg in #2582) does not pass to a *const i8 parameter without a cast, and a c_char value does not store through a *mut i8.

Expected: the standard library spells C's char as c_char in every position, as the spec writes it (*const c_char, 016_ffi.md), so a program compiles the same on both char signednesses.

Found while cutting the linux-aarch64 seed (#2582); the compiler side (src/compiler/ClangBridge.w) is fixed on branch charptr.

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    This now blocks the linux-aarch64 seed leg (#2582): c-migrator-core-tests check-posix-path-calls migrates realpath(".", resolved) to var result: *mut c_char = realpath(c".".ptr, &resolved[0] as *mut c_char); on AArch64 Linux the unit's c_char is u8 while std.libc's realpath returns *mut i8, and the mismatch surfaces as an ICE in MIR ("use rvalue type is incompatible with assign destination") rather than a Sema diagnostic — a second defect (D65: Sema accepted a *mut i8 value for a *mut u8 binding). The x86_64 and Windows legs are unaffected (signed char). Needs: a target-aware c_char the standard library itself declares and spells its C strings with, and Sema refusing the pointer mismatch.

  2. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Ruled (Eric, 2026-10-23), recorded as D155: a migrated corpus never contains a concrete value for a c_* alias (corpora import std's target-resolved aliases; c_long falls out with c_char); c_char is the target's everywhere; c"…" is *const c_char; a pointer to one integer type is not a pointer to another, with the fix-it p as *const c_char, landed last with a fixture per target. Facades written against c_char stay portable without edits. Order: std.libc aliases and C strings → the literal and the runtime's parameters → the migrator emits no type c_*, every corpus re-promoted under ruling:D155 and tested on AArch64 Linux and Windows → the Sema diagnostic → the aarch64 seed leg.

  3. ehartford commented on Oct 24, 2026

    @ehartford
    ContributorAuthor

    Implemented and merged as f36cf4f (#2596) under rulings D155 and D156: the C aliases are the target's builtins, the migrator spells fixed widths with c_char symbolic and records the data model, the D65 pointer rule is in with its p as *const c_char fix-it, all six corpora re-promoted. Remaining, tracked in handoff.md: the corpus tests on eric-5090/win10, a D155 Darwin seed cut (after which the interim i8 casts in src/ and the fixtures' c"…".ptr as *const i8 casts become c_char), then the linux-aarch64 seed leg (#2582).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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