v4/lib: add regression test for nested union with pointer member (issue #47)

Summary

Add regression test for issue #47 (closed): nested union with pointer member.

This test exercises the scenario that was broken before commit d32226db: nested unions whose active member is a struct containing a pointer, with a larger alternative member. The old arrayElemOff heuristic produced _ [-16]byte (invalid Go); the fix (pre := lcaOff - off0) computes the correct padding.

What's included

  • testdata/issue47.c — standalone C test case (also picked up by TestOther in the root package)
  • v4/lib/issue47_test.go — Go regression test that:
    1. Compiles the C source with hostCC and records the expected output
    2. Transpiles it with ccgo (NewTask)
    3. Builds the generated Go with go build
    4. Runs both binaries and compares their output

Test results

=== RUN   TestIssue47Regression
    issue47_test.go:101: ccgo OK
    issue47_test.go:134: output: a0=1 a1=3 PASS
--- PASS: TestIssue47Regression (5.31s)

TestGoAlign and TestSep also pass with no regressions.

Refs: #47 (closed)

Merge request reports

Loading