From 15f9782feb2d5852653fd7ae7d02acfb60b76bf5 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Wed, 20 Nov 2019 15:12:11 -0500 Subject: [PATCH 1/2] [Runtime] Update cflags and fix warnings accordingly. Update flags: * Add -Werror so that warnings are errors. * Move to -Wconversion that adds: * -Wbitfield-enum-conversion * -Wbool-conversion * -Wconstant-conversion * -Wenum-conversion * -Wfloat-conversion * -Wimplicit-float-conversion * -Wimplicit-int-conversion * -Wint-conversion * -Wliteral-conversion * -Wnon-literal-null-conversion * -Wnull-conversion * -Wobjc-literal-conversion * -Wshorten-64-to-32 * -Wsign-conversion * -Wstring-conversion Last work related to: https://github.com/xamarin/xamarin-macios/pull/7405 --- Make.config | 2 +- runtime/runtime.m | 4 ++-- runtime/xamarin/runtime.h | 2 +- tests/test-libraries/libtest.m | 12 +++++++++--- tools/common/StaticRegistrar.cs | 8 ++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Make.config b/Make.config index 927ecc11b30c..371944dc1bc2 100644 --- a/Make.config +++ b/Make.config @@ -190,7 +190,7 @@ IOS_CXX=$(XCODE_CXX) SIMULATOR_BIN_PATH=$(XCODE_DEVELOPER_ROOT)/Platforms/iPhoneSimulator.platform/Developer/usr/bin SIMULATOR_CC=$(IOS_CC) -CFLAGS= -Wall -fms-extensions -Wno-format-security -Wsign-compare -Wshorten-64-to-32 -Wsign-conversion -Wdeprecated -Wuninitialized -fstack-protector-strong +CFLAGS= -Wall -fms-extensions -Werror -Wconversion -Wdeprecated -Wuninitialized -fstack-protector-strong ifdef ENABLE_BITCODE_ON_IOS BITCODE_CFLAGS=-fembed-bitcode-marker diff --git a/runtime/runtime.m b/runtime/runtime.m index 2de6c4bcc603..843ae4dd0954 100644 --- a/runtime/runtime.m +++ b/runtime/runtime.m @@ -495,7 +495,7 @@ void xamarin_framework_peer_unlock () // The XamarinExtendedObject protocol is just to avoid a // compiler warning (no 'xamarinGetGChandle' selector found). @protocol XamarinExtendedObject --(int) xamarinGetGCHandle; +-(uint32_t) xamarinGetGCHandle; -(void) xamarinSetGCHandle: (uint32_t) gc_handle; @end @@ -2809,7 +2809,7 @@ -(void) dealloc */ @implementation NSObject (NonXamarinObject) --(int) xamarinGetGCHandle +-(uint32_t) xamarinGetGCHandle { // COOP: no managed memory access: any mode. return 0; diff --git a/runtime/xamarin/runtime.h b/runtime/xamarin/runtime.h index a65b6036d586..9867bc9376d7 100644 --- a/runtime/xamarin/runtime.h +++ b/runtime/xamarin/runtime.h @@ -297,7 +297,7 @@ class XamarinObject { @end @interface NSObject (NonXamarinObject) --(int) xamarinGetGCHandle; +-(uint32_t) xamarinGetGCHandle; @end #endif diff --git a/tests/test-libraries/libtest.m b/tests/test-libraries/libtest.m index 09504f3fef02..1bd4170e8887 100644 --- a/tests/test-libraries/libtest.m +++ b/tests/test-libraries/libtest.m @@ -506,7 +506,7 @@ -(void) setProtocol -(void) completedSetProtocol: (id) value { - assert (!"THIS FUNCTION SHOULD BE OVERRIDDEN"); + assert (false); // "THIS FUNCTION SHOULD BE OVERRIDDEN"; } @end @@ -602,7 +602,7 @@ + (void)setTestClass:(Class) value { -(void) classCallback: (void (^)(int32_t magic_number))completionHandler { - assert (!"THIS FUNCTION SHOULD BE OVERRIDDEN"); + assert (false); //!"THIS FUNCTION SHOULD BE OVERRIDDEN" } -(void) callClassCallback @@ -730,7 +730,7 @@ -(void) callAssertMainThreadBlockReleaseCallbackQOS -(void) assertMainThreadBlockReleaseCallback: (innerBlock) completionHandler { - assert (!"THIS FUNCTION SHOULD BE OVERRIDDEN"); + assert (false); //!"THIS FUNCTION SHOULD BE OVERRIDDEN"); } -(void) testFreedBlocks @@ -756,7 +756,10 @@ +(int) calledBlockCount static void block_called () { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" OSAtomicIncrement32 (&called_blocks); +#pragma clang diagnostic pop } +(void) callProtocolWithBlockProperties: (id) obj required: (bool) required instance: (bool) instance; @@ -821,7 +824,10 @@ +(void) setProtocolWithBlockProperties: (id) obj re @implementation FreedNotifier -(void) dealloc { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" OSAtomicIncrement32 (&freed_blocks); +#pragma clang diagnostic pop [super dealloc]; } @end diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 1676f6fd1b11..4da7a467581a 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -2523,9 +2523,9 @@ string GetObjCSignature (ObjCMethod method, List exceptions) else if (method.CurrentTrampoline == Trampoline.Release) return "-(void) release"; else if (method.CurrentTrampoline == Trampoline.GetGCHandle) - return "-(int) xamarinGetGCHandle"; + return "-(uint32_t) xamarinGetGCHandle"; else if (method.CurrentTrampoline == Trampoline.SetGCHandle) - return "-(void) xamarinSetGCHandle: (int) gchandle"; + return "-(void) xamarinSetGCHandle: (uint32_t) gchandle"; #if MONOMAC else if (method.CurrentTrampoline == Trampoline.CopyWithZone1 || method.CurrentTrampoline == Trampoline.CopyWithZone2) return "-(id) copyWithZone: (NSZone *)zone"; @@ -3154,14 +3154,14 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List sb.WriteLine (); return; case Trampoline.GetGCHandle: - sb.WriteLine ("-(int) xamarinGetGCHandle"); + sb.WriteLine ("-(uint32_t) xamarinGetGCHandle"); sb.WriteLine ("{"); sb.WriteLine ("return __monoObjectGCHandle.gc_handle;"); sb.WriteLine ("}"); sb.WriteLine (); return; case Trampoline.SetGCHandle: - sb.WriteLine ("-(void) xamarinSetGCHandle: (int) gc_handle"); + sb.WriteLine ("-(void) xamarinSetGCHandle: (uint32_t) gc_handle"); sb.WriteLine ("{"); sb.WriteLine ("__monoObjectGCHandle.gc_handle = gc_handle;"); sb.WriteLine ("__monoObjectGCHandle.native_object = self;"); From eefc930850eb3be953a052255cbfa2536e610c60 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Mon, 25 Nov 2019 11:36:54 -0500 Subject: [PATCH 2/2] Apply suggestions from code review --- tests/test-libraries/libtest.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-libraries/libtest.m b/tests/test-libraries/libtest.m index 1bd4170e8887..a721f0126442 100644 --- a/tests/test-libraries/libtest.m +++ b/tests/test-libraries/libtest.m @@ -602,7 +602,7 @@ + (void)setTestClass:(Class) value { -(void) classCallback: (void (^)(int32_t magic_number))completionHandler { - assert (false); //!"THIS FUNCTION SHOULD BE OVERRIDDEN" + assert (false); // THIS FUNCTION SHOULD BE OVERRIDDEN } -(void) callClassCallback @@ -730,7 +730,7 @@ -(void) callAssertMainThreadBlockReleaseCallbackQOS -(void) assertMainThreadBlockReleaseCallback: (innerBlock) completionHandler { - assert (false); //!"THIS FUNCTION SHOULD BE OVERRIDDEN"); + assert (false); // THIS FUNCTION SHOULD BE OVERRIDDEN } -(void) testFreedBlocks