Skip to content

Commit 702b903

Browse files
authored
[runtime] Adopt safer native compiler flags: Wcast-function-type-mismatch (#24083)
Example warning: ``` macios/runtime/trampolines.m:1784:9: error: cast from 'void *(*)(MonoObject *, void *, GCHandle *)' (aka 'void *(*)(_MonoObject *, void *, void **)') to 'xamarin_managed_to_id_func' (aka 'id (*)(_MonoObject *, void *, void **)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch] 1784 | return (xamarin_managed_to_id_func) xamarin_smart_enum_to_nsstring; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` References: * https://developer.apple.com/documentation/xcode/enabling-enhanced-security-for-your-app * https://releases.llvm.org/8.0.0/tools/clang/docs/ReleaseNotes.html#major-new-features (for -ftrivial-auto-var-init=zero) Contributes towards #23023.
1 parent 154bd46 commit 702b903

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

mk/rules.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CFLAGS=\
3838
-Wno-objc-protocol-property-synthesis \
3939
-Wignored-qualifiers \
4040
-Wmissing-field-initializers \
41+
-Wcast-function-type-mismatch \
4142
-g \
4243
-I.
4344
SWIFTFLAGS=-g -emit-library

runtime/trampolines.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@
714714
xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);
715715

716716
// Call the managed implementation
717-
id (*invoke) (id, SEL, NSZone*) = (id (*)(id, SEL, NSZone*)) xamarin_trampoline;
717+
id (*invoke) (id, SEL, NSZone*) = (id (*)(id, SEL, NSZone*)) (void *) xamarin_trampoline;
718718
rv = invoke (self, sel, zone);
719719

720720
// Restore our GCHandle
@@ -1674,7 +1674,7 @@
16741674
return (xamarin_managed_to_id_func) xamarin_get_nsvalue_converter (managedType, method, false, exception_gchandle);
16751675
}
16761676

1677-
void *
1677+
id
16781678
xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle)
16791679
{
16801680
guint32 context_ref = GPOINTER_TO_UINT (context);

runtime/xamarin/trampolines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ NSArray * xamarin_convert_managed_to_nsarray_with_func (MonoArray *array, xama
121121
MonoArray * xamarin_convert_nsarray_to_managed_with_func (NSArray *array, MonoClass *managedElementType, xamarin_id_to_managed_func convert, void *context, GCHandle *exception_gchandle);
122122

123123
void * xamarin_nsstring_to_smart_enum (id value, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);
124-
void * xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle);
124+
id xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle);
125125

126126
// Returns a pointer to the value type, which must be freed using xamarin_free.
127127
void *xamarin_nsnumber_to_bool (NSNumber *number, void *ptr, MonoClass *managedType, void *context, GCHandle *exception_gchandle);

0 commit comments

Comments
 (0)