mem: reject call-conv mismatches at bare-fn → fn-ptr coercion
Passing a default-conv sx function to a `callconv(.c)` fn-pointer slot (e.g. pthread_create's start routine) used to silently mismatch ABIs: the C-side caller didn't supply __sx_ctx, so the sx-side body read its first user param as garbage. The bug surfaced as a SIGSEGV inside ANativeWindow_setBuffersGeometry on Android during chess bringup. Now the compiler rejects the coercion outright at the bare-fn name lookup site: error: call-convention mismatch: 'sx_handler' is declared with default sx convention but the target type expects callconv(.c) Also: `#foreign` declarations without an explicit `callconv` now default to `.c` instead of `.default`. Every external C symbol is by definition C-conv; the previous default silently typed `objc_msgSend` (et al.) as default-conv, so the check would fire on the consumer side when the user typed a fn-ptr as `callconv(.c)`. With the foreign-default fix, the existing typed-msgSend casts in `std/objc.sx` and `gpu/metal.sx` keep type-checking and the rule is "C-conv on both sides or neither." Caught by the new check (fixed in the same commit): - `ios_gl_proc` in `platform/uikit.sx` lacked callconv(.c) but was passed to `load_gl` whose `get_proc` slot expects it. - `ffi_apply_callback` / `ffi_apply_callback2` in `examples/ffi-06-callback.sx` had default-conv fn-ptr params but the C bodies (in the companion .c) are unambiguously C-conv. Regression test: `examples/131-callconv-mismatch-diagnostic.sx` locks in the diagnostic shape (sx-conv fn → callconv(.c) slot). 153/153 example tests pass. Chess green on macOS / iOS sim / Android.
This commit is contained in:
1
tests/expected/131-callconv-mismatch-diagnostic.exit
Normal file
1
tests/expected/131-callconv-mismatch-diagnostic.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
1
tests/expected/131-callconv-mismatch-diagnostic.txt
Normal file
1
tests/expected/131-callconv-mismatch-diagnostic.txt
Normal file
@@ -0,0 +1 @@
|
||||
/Users/agra/projects/sx/examples/131-callconv-mismatch-diagnostic.sx:12:42: error: call-convention mismatch: 'sx_handler' is declared with default sx convention but the target type expects callconv(.c)
|
||||
@@ -334,5 +334,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -306,5 +306,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -307,5 +307,3 @@ declare ptr @sx_jni_env_tl_get() #0
|
||||
declare void @sx_jni_env_tl_set(ptr) #0
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
|
||||
|
||||
@@ -390,5 +390,3 @@ entry:
|
||||
store ptr %selN, ptr @OBJC_SELECTOR_REFERENCES_release, align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3281,5 +3281,3 @@ entry:
|
||||
store ptr %sel, ptr @OBJC_SELECTOR_REFERENCES_tripleValue, align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user