From 369c84db35a6a1e94f8a4689a695fabdac056166 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 1 Apr 2019 11:26:46 +0100 Subject: [PATCH] Fix compiler warnings. --- Test/AssociatedObject2.m | 2 +- Test/ExceptionTest.m | 1 + Test/IVarSuperclassOverlap.m | 6 ++++-- Test/ManyManySelectors.m | 4 ++++ Test/PropertyAttributeTest.m | 2 +- Test/ProtocolCreation.m | 1 + Test/setSuperclass.m | 5 ----- Test/zeroSizedIVar.m | 1 - arc.m | 5 ----- encoding2.c | 5 ++++- ivar.c | 2 -- ivar.h | 2 +- loader.c | 1 - method.h | 2 +- properties.h | 2 +- protocol.c | 1 - protocol.h | 2 +- runtime.c | 1 - 18 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Test/AssociatedObject2.m b/Test/AssociatedObject2.m index e8f7d53..0d958c0 100644 --- a/Test/AssociatedObject2.m +++ b/Test/AssociatedObject2.m @@ -25,7 +25,6 @@ int main() tc = [MLTestClass new]; objc_setAssociatedObject(tc, &static_char, (id)1223, OBJC_ASSOCIATION_ASSIGN); [tc release]; - int i = 0; tc = [MLTestClass new]; objc_setAssociatedObject(tc, &static_char, (id)1223, OBJC_ASSOCIATION_ASSIGN); SEL some_sel = sel_registerName(".some_sel"); @@ -33,5 +32,6 @@ int main() class_addMethod(object_getClass(tc), some_sel, (IMP)ff, types); int j = (int)objc_getAssociatedObject(tc, &static_char); + assert(j == 1223); [tc release]; } diff --git a/Test/ExceptionTest.m b/Test/ExceptionTest.m index d009b7f..5a7295c 100644 --- a/Test/ExceptionTest.m +++ b/Test/ExceptionTest.m @@ -27,6 +27,7 @@ int finally(void) { __attribute__((cleanup(runCleanup))) int x; + (void)x; @try { throw(); } @finally { finallyEntered = YES; } return 0; diff --git a/Test/IVarSuperclassOverlap.m b/Test/IVarSuperclassOverlap.m index 21beb2f..3a10f3f 100644 --- a/Test/IVarSuperclassOverlap.m +++ b/Test/IVarSuperclassOverlap.m @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) Ivar b1 = class_getInstanceVariable(swb, "b1"); Ivar b2 = class_getInstanceVariable(swb, "b2"); Ivar b3 = class_getInstanceVariable(swb, "b3"); - Ivar b4 = class_getInstanceVariable(swb, "b3"); + Ivar b4 = class_getInstanceVariable(swb, "b4"); Ivar notBitfield = class_getInstanceVariable(swb, "notBitfield"); assert(baseSmall); assert(c1); @@ -53,6 +53,8 @@ int main(int argc, char *argv[]) assert(b1); assert(b2); assert(b3); + assert(b4); + assert(notBitfield); StartsWithBitfield *swbi = [StartsWithBitfield new]; // Alternating 01 bit pattern, should catch small overwrites. @@ -77,8 +79,8 @@ int main(int argc, char *argv[]) assert(swbi->b3 == 5); assert(swbi->b4 == 11); - ptrdiff_t baseSmallOffset = ivar_getOffset(baseSmall); #ifdef NEW_ABI + ptrdiff_t baseSmallOffset = ivar_getOffset(baseSmall); // These should pass with the old ABI, but they don't at the moment. The // way that they don't is not very harmful though: we just get a bit of // redundant padding, so I don't consider a fix a very high priority. diff --git a/Test/ManyManySelectors.m b/Test/ManyManySelectors.m index 2c65212..c859f10 100644 --- a/Test/ManyManySelectors.m +++ b/Test/ManyManySelectors.m @@ -13,6 +13,10 @@ static char selBuffer[] = "XXXXXXXselectorXXXXXXXX"; static id x(id self, SEL _cmd) { methodCalled = YES; + if (strcmp(selBuffer, sel_getName(_cmd)) != 0) + { + fprintf(stderr, "'%s' != '%s'\n", selBuffer, sel_getName(_cmd)); + } assert(strcmp(selBuffer, sel_getName(_cmd)) == 0); return self; } diff --git a/Test/PropertyAttributeTest.m b/Test/PropertyAttributeTest.m index de52d79..b9ff092 100644 --- a/Test/PropertyAttributeTest.m +++ b/Test/PropertyAttributeTest.m @@ -31,7 +31,7 @@ __attribute__((objc_root_class)) int main() { - unsigned int outCount, i; + unsigned int outCount; objc_property_t *properties = class_copyPropertyList([helloclass class], &outCount); assert(outCount == 1); objc_property_t property = properties[0]; diff --git a/Test/ProtocolCreation.m b/Test/ProtocolCreation.m index a31e9cf..fb933e7 100644 --- a/Test/ProtocolCreation.m +++ b/Test/ProtocolCreation.m @@ -25,6 +25,7 @@ void checkProtocolMethod(Protocol *p, SEL sel, BOOL isClass, BOOL isOptional) int main(void) { + __attribute__((unused)) Protocol *force_reference = @protocol(Test2); Protocol *p = objc_allocateProtocol("Test"); protocol_addMethodDescription(p, @selector(someClassMethod), "@:", YES, NO); diff --git a/Test/setSuperclass.m b/Test/setSuperclass.m index 27994e0..ba2f4d7 100644 --- a/Test/setSuperclass.m +++ b/Test/setSuperclass.m @@ -166,9 +166,6 @@ static int failures = 0; } while(0) int main(int argc, char **argv) { - Class firstSuperclass = objc_getClass("DefaultSuperclass"); - Class subclass1 = objc_getClass("Subclass1"); - /* Transitioning to a new superclass before +initialize has been called */ { Class subclass1 = objc_getClass("Subclass1"); @@ -232,8 +229,6 @@ int main(int argc, char **argv) { class_setSuperclass(subclass2, secondSuperclass); assert(_notInitializedSuperclass2Initialized); - Subclass2 *subclass2instance2 = class_createInstance(subclass2, 0); - // CLASS // can call method on subclass expect([subclass2instance1 existsOnSubclass2]); diff --git a/Test/zeroSizedIVar.m b/Test/zeroSizedIVar.m index 80690b4..2200536 100644 --- a/Test/zeroSizedIVar.m +++ b/Test/zeroSizedIVar.m @@ -43,7 +43,6 @@ int main() assert(class_getInstanceSize(nsarray) == (sizeof(Class) + sizeof(NSUInteger))); Ivar count = class_getInstanceVariable(nsarray, "count"); assert(ivar_getOffset(count) == sizeof(id)); - Ivar objects = class_getInstanceVariable(nsarray, "objects"); Class bitfield = objc_getClass("BitfieldTest"); assert(bitfield); diff --git a/arc.m b/arc.m index edd943c..ad7d4f2 100644 --- a/arc.m +++ b/arc.m @@ -109,8 +109,6 @@ static inline struct arc_tls* getARCThreadData(void) return tls; #endif } -static int count = 0; -static int poolCount = 0; static inline void release(id obj); /** @@ -151,7 +149,6 @@ static void emptyPool(struct arc_tls *tls, id *stop) // This may autorelease some other objects, so we have to work in // the case where the autorelease pool is extended during a -release. release(*tls->pool->insert); - count--; } void *old = tls->pool; tls->pool = tls->pool->previous; @@ -163,7 +160,6 @@ static void emptyPool(struct arc_tls *tls, id *stop) (tls->pool->insert > tls->pool->pool)) { tls->pool->insert--; - count--; release(*tls->pool->insert); } } @@ -405,7 +401,6 @@ static inline id autorelease(id obj) pool->insert = pool->pool; tls->pool = pool; } - count++; *pool->insert = obj; pool->insert++; return obj; diff --git a/encoding2.c b/encoding2.c index ee03f4d..6a50ff5 100644 --- a/encoding2.c +++ b/encoding2.c @@ -419,7 +419,10 @@ void method_getArgumentType(Method method, const char *types = findParameterStart(method_getTypeEncoding(method), index); if (NULL == types) { - strncpy(dst, "", dst_len); + if (dst_len > 0) + { + *dst = '\0'; + } return; } size_t length = lengthOfTypeEncoding(types); diff --git a/ivar.c b/ivar.c index 92af800..99c4c13 100644 --- a/ivar.c +++ b/ivar.c @@ -14,7 +14,6 @@ ptrdiff_t objc_sizeof_type(const char *); PRIVATE void objc_compute_ivar_offsets(Class class) { - struct objc_ivar_list_legacy *legacy = NULL; if (class->ivars == NULL) { Class super_class = class_getSuperclass(class); @@ -47,7 +46,6 @@ PRIVATE void objc_compute_ivar_offsets(Class class) } ivar_start = super->instance_size; } - long class_size = 0 - class->instance_size; class->instance_size = ivar_start; /* For each instance variable, we add the offset if required (it will be zero * if this class is compiled with a static ivar layout). We then set the diff --git a/ivar.h b/ivar.h index 367e57b..67abd0c 100644 --- a/ivar.h +++ b/ivar.h @@ -180,7 +180,7 @@ struct objc_ivar_list * `objc_ivar` structs, which have fields appended that this version of the * runtime does not know about. */ -static struct objc_ivar *ivar_at_index(struct objc_ivar_list *l, int i) +static inline struct objc_ivar *ivar_at_index(struct objc_ivar_list *l, int i) { assert(l->size >= sizeof(struct objc_ivar)); return (struct objc_ivar*)(((char*)l->ivar_list) + (i * l->size)); diff --git a/loader.c b/loader.c index 8c0ed4d..9b6d060 100644 --- a/loader.c +++ b/loader.c @@ -231,7 +231,6 @@ OBJC_PUBLIC void __objc_load(struct objc_init *init) } objc_register_selector(sel); } - int i = 0; for (struct objc_protocol *proto = init->proto_begin ; proto < init->proto_end ; proto++) { diff --git a/method.h b/method.h index 9eb0ef4..4e2997b 100644 --- a/method.h +++ b/method.h @@ -77,7 +77,7 @@ struct objc_method_list * `objc_method` structs, which have fields appended that this version of the * runtime does not know about. */ -static struct objc_method *method_at_index(struct objc_method_list *l, int i) +static inline struct objc_method *method_at_index(struct objc_method_list *l, int i) { assert(l->size >= sizeof(struct objc_method)); return (struct objc_method*)(((char*)l->methods) + (i * l->size)); diff --git a/properties.h b/properties.h index aa3724d..02f2511 100644 --- a/properties.h +++ b/properties.h @@ -217,7 +217,7 @@ struct objc_property_list * `objc_property` structs, which have fields appended that this version of the * runtime does not know about. */ -static struct objc_property *property_at_index(struct objc_property_list *l, int i) +static inline struct objc_property *property_at_index(struct objc_property_list *l, int i) { assert(l->size >= sizeof(struct objc_property)); return (struct objc_property*)(((char*)l->properties) + (i * l->size)); diff --git a/protocol.c b/protocol.c index 88e46bb..dd1061e 100644 --- a/protocol.c +++ b/protocol.c @@ -705,7 +705,6 @@ void protocol_addProperty(Protocol *aProtocol, } struct objc_property_list *list = *listPtr; int index = list->count-1; - const char *iVarName = NULL; struct objc_property p = propertyFromAttrs(attributes, attributeCount, name); assert(list->size == sizeof(p)); memcpy(&(list->properties[index]), &p, sizeof(p)); diff --git a/protocol.h b/protocol.h index d27f68c..15a0838 100644 --- a/protocol.h +++ b/protocol.h @@ -79,7 +79,7 @@ struct objc_protocol_method_description_list * array of some future version of these structs, which have fields appended * that this version of the runtime does not know about. */ -static struct objc_protocol_method_description * +static inline struct objc_protocol_method_description * protocol_method_at_index(struct objc_protocol_method_description_list *l, int i) { assert(l->size >= sizeof(struct objc_protocol_method_description)); diff --git a/runtime.c b/runtime.c index 245ef03..b297f43 100644 --- a/runtime.c +++ b/runtime.c @@ -782,7 +782,6 @@ void *object_getIndexedIvars(id obj) size_t size = classForObject(obj)->instance_size; if ((0 == size) && class_isMetaClass(classForObject(obj))) { - Class cls = (Class)obj; size = sizeof(struct objc_class); } return ((char*)obj) + size;