0
0
Fork 0
mirror of https://git.code.sf.net/p/quake/quakeforge synced 2025-03-21 18:01:15 +00:00

[qfcc] Add failing test for dealloc warning

I have gotten tired of chasing memory leaks caused by me forgetting to
add [super dealloc] to my dealloc methods, so getting qfcc to chew me
out when I do seems to be a good idea (having such a warning would have
saved me many hours, just as missing return warnings have).
This commit is contained in:
Bill Currie 2021-12-24 09:53:58 +09:00
parent 5bfe0e5d34
commit bdd3870d2f
3 changed files with 86 additions and 0 deletions

View file

@ -17,6 +17,7 @@ test_progs_dat=\
tools/qfcc/test/comma-expr.dat \
tools/qfcc/test/compound.dat \
tools/qfcc/test/deadbool.dat \
tools/qfcc/test/dealloc-nowarn.dat \
tools/qfcc/test/double.dat \
tools/qfcc/test/double-alias.dat \
tools/qfcc/test/enum.dat \
@ -63,6 +64,7 @@ fail_progs_dat=
test_build_errors=\
tools/qfcc/test/classarray.r \
tools/qfcc/test/dealloc-warn.r \
tools/qfcc/test/double-demote-float.r \
tools/qfcc/test/double-demote-float-ainit.r \
tools/qfcc/test/double-demote-float-ginit.r \
@ -193,6 +195,16 @@ tools/qfcc/test/deadbool.run: $(qfcc_test_run_deps)
include $(deadbool_dep) # am--include-marker
r_depfiles_remade += $(deadbool_dep)
tools_qfcc_test_dealloc_nowarn_dat_SOURCES=tools/qfcc/test/dealloc-nowarn.r
dealloc_nowarn_obj=$(tools_qfcc_test_dealloc_nowarn_dat_SOURCES:.r=.o)
dealloc_nowarn_dep=$(call qcautodep,$(tools_qfcc_test_dealloc_nowarn_dat_SOURCES))
tools/qfcc/test/dealloc-nowarn.dat$(EXEEXT): $(dealloc_nowarn_obj) $(QFCC_DEP)
$(V_QFCCLD)$(QLINK) -o $@ $(dealloc_nowarn_obj)
tools/qfcc/test/dealloc-nowarn.run: $(qfcc_test_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-run $@
include $(dealloc_nowarn_dep) # am--include-marker
r_depfiles_remade += $(dealloc_nowarn_dep)
tools_qfcc_test_double_dat_SOURCES=tools/qfcc/test/double.r
double_obj=$(tools_qfcc_test_double_dat_SOURCES:.r=.o)
double_dep=$(call qcautodep,$(tools_qfcc_test_double_dat_SOURCES))
@ -216,6 +228,9 @@ r_depfiles_remade += $(double_alias_dep)
tools/qfcc/test/classarray.run$(EXEEXT): tools/qfcc/test/classarray.r $(qfcc_fail_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
tools/qfcc/test/dealloc-warn.run$(EXEEXT): tools/qfcc/test/dealloc-warn.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) $<

View file

@ -0,0 +1,36 @@
@interface Object
{
Class isa;
}
-(void)dealloc;
@end
@interface derived : Object
@end
@implementation Object
-(void) dealloc
{
// this is the root of the hierarchy, so no super to call, thus
// must not check for [super dealloc]
}
@end
void __obj_exec_class (struct obj_module *msg) = #0;
id obj_msgSend_super (Super *class, SEL op, ...) = #0;
@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)
[super dealloc];
}
@end
int main ()
{
return 0; // test passes if compile succeeds (with -Werror)
}

View file

@ -0,0 +1,35 @@
@interface Object
{
Class isa;
}
-(void)dealloc;
@end
@interface derived : Object
@end
@implementation Object
-(void) dealloc
{
// this is the root of the hierarchy, so no super to call, thus
// must not check for [super dealloc]
}
@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)
}
@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)
}