From a5f82004bc8ad6b17da14abbbc5ce87d8c3a6f91 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 26 Feb 2023 15:48:04 +0900 Subject: [PATCH] [qfcc] Add failing test for super dealloc While working on vkgen, I found a dealloc that wasn't calling [super dealloc] but qfcc hadn't noticed it. --- tools/qfcc/test/Makemodule.am | 4 +++ tools/qfcc/test/dealloc-warn4.r | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tools/qfcc/test/dealloc-warn4.r diff --git a/tools/qfcc/test/Makemodule.am b/tools/qfcc/test/Makemodule.am index 0d4fa5c2a..ea2ba9f70 100644 --- a/tools/qfcc/test/Makemodule.am +++ b/tools/qfcc/test/Makemodule.am @@ -81,6 +81,7 @@ test_build_errors=\ tools/qfcc/test/dealloc-warn.r \ tools/qfcc/test/dealloc-warn2.r \ tools/qfcc/test/dealloc-warn3.r \ + tools/qfcc/test/dealloc-warn4.r \ tools/qfcc/test/double-demote-float.r \ tools/qfcc/test/double-demote-float-ainit.r \ tools/qfcc/test/double-demote-float-ginit.r \ @@ -277,6 +278,9 @@ tools/qfcc/test/dealloc-warn2.run$(EXEEXT): tools/qfcc/test/dealloc-warn2.r $(qf tools/qfcc/test/dealloc-warn3.run$(EXEEXT): tools/qfcc/test/dealloc-warn3.r $(qfcc_fail_run_deps) @$(top_srcdir)/tools/qfcc/test/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $< +tools/qfcc/test/dealloc-warn4.run$(EXEEXT): tools/qfcc/test/dealloc-warn4.r $(qfcc_fail_run_deps) + @$(top_srcdir)/tools/qfcc/test/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $< + tools/qfcc/test/double-demote-int.run$(EXEEXT): tools/qfcc/test/double-demote-int.r $(qfcc_fail_run_deps) @$(top_srcdir)/tools/qfcc/test/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $< diff --git a/tools/qfcc/test/dealloc-warn4.r b/tools/qfcc/test/dealloc-warn4.r new file mode 100644 index 000000000..9962e19ca --- /dev/null +++ b/tools/qfcc/test/dealloc-warn4.r @@ -0,0 +1,51 @@ +#pragma warn error +#pragma optimize on + +void str_free(string str) +{ +} + +@interface Object +{ + Class isa; +} +-(void)dealloc; +@end + +@interface derived : Object +{ + int free; + string foo; + id bar; +} +@end + +@implementation Object +-(void) dealloc +{ + // this is the root of the hierarchy, so no super to call, thus + // must not check for [super dealloc] +} +-(void) release +{ +} +@end + +@implementation derived +-(void) dealloc +{ + // as this is a derived class, failure to call [super dealloc] will + // result in a memory leak (yes, there could be special allocators + // involved, in which case something will be needed to inform the + // compiler) + str_free (foo); +} +@end + +void __obj_exec_class (struct obj_module *msg) = #0; +id obj_msgSend_super (Super *class, SEL op, ...) = #0; + +int main () +{ + return 1; // test fails if compile succeeds (with -Werror) +}