Skip to content

Silent wrong layout: two modules declaring a same-named type share one LLVM struct in codegen #1446

Closed

Description

@ehartford

Summary

Two modules that each declare a type with the same name get one LLVM struct in codegen: the program reads one module's values through the other's layout — silent wrong code.

Repro (origin/main 1c76062)

lib/dupa1430.w:

pub type Item { x: i64, y: i64 }
pub fn make_a() -> Item: Item { x: 1111111111111, y: 2222222222222 }
pub fn show_a(i: &Item) -> Unit: print(f"a {i.x} {i.y}")

lib/dupb1430.w:

pub type Item { s: str, k: i32 }
pub fn make_b() -> Item: Item { s: "bee", k: 7 }
pub fn show_b(i: &Item) -> Unit: print(f"b {i.s} {i.k}")

root:

use dupa1430
use dupb1430

fn main:
    let a = make_a()
    show_a(&a)
    let b = make_b()
    show_b(&b)

Prints a 1724130190 / b bee 7; expected a 1111111111111 2222222222222.

Where

src/Codegen.w Pass 0a/0b key named LLVM types by the declaration's bare name symbol (self.pool.get_data0(decl)), so both Item declarations register the same struct_type_map entry and the later declaration's body overwrites the first's (declare_struct_type sets the one named struct's body twice). Sema already distinguishes the two types; codegen needs a per-declaration (module-qualified) type identity. (#1430 keeps the existing first-declaration behavior for a reference and does not change this.)

Activity

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