Files
sx/examples/1207-ffi-extern-global-from-helper.sx
agra b52d424369 refactor(ffi-linkage): Phase 9.3 — rename *-foreign* example files → extern/runtime names
git-mv the 10 foreign-named example families to extern/runtime-class names + update
every #import/#include/#source ref, stale comment ref, and the 1172 stderr snapshot
(path + 'extern symbol' message). Renames: 0729…-foreign→…-extern, 1172-diagnostics-
foreign-symbol-conflict→…-extern-symbol-conflict, 1205/1207 ffi-foreign-global→
ffi-extern-global, 1216/1217 ffi-…-foreign-(in-method|result-chain)→…-extern-…,
1219-ffi-foreign→1219-ffi-extern, 1306 objc-foreign-class-chained→objc-runtime-class-
chained, 1318 objc-property-foreign→objc-property-extern-class. DEDUP: deleted
1218-ffi-foreign-cvariadic (identical to 1229-ffi-extern-cvariadic; updated 1229's
twin ref) + the orphaned 1620 dir. Also purged editors/vscode tmLanguage (#foreign
dropped from the directive highlighter) + 1220.h/issues-0030.sx comment refs. Suite
green (644 corpus / 443 unit, 0 failed).
2026-06-15 11:14:35 +03:00

29 lines
943 B
Plaintext

// `xx @<extern_global>` round-trips through a non-main helper
// function: the helper's `xx @__stdinp` cast lowers to a `bitcast`
// IR opcode that emit_llvm.zig dispatches to `LLVMBuildPtrToInt`
// (BitCast doesn't accept ptr↔int on modern LLVM with opaque
// pointers), and a `u64`-returning function correctly returns
// the address.
//
// Was issue-0037 — the helper used to emit `ret i64 undef` because
// `coerceToType` had no pointer↔integer case, so the explicit
// `xx ptr` cast produced an unchanged pointer value handed to a
// `ret i64` slot.
#import "modules/std.sx";
__stdinp : *void extern;
stdinp_addr_via_helper :: () -> u64 {
xx @__stdinp
}
main :: () -> i32 {
direct : u64 = xx @__stdinp;
via_helper := stdinp_addr_via_helper();
print("direct non-null = {}\n", direct != 0);
print("helper non-null = {}\n", via_helper != 0);
print("eq = {}\n", direct == via_helper);
0
}