1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-25 08:12:11 -07:00

Turn on -wunreachable-code for gcc and clang.

Remove unreachable code:
* No need to have different debug options or structured allocation classes for different platforms.
* Don't use STATISTIC_BEGIN, use STATISTIC_STAT.
* #ifdef away the unused code in zmess.c for testing ControlAlloc failure.
* Remove unused code from the example Scheme interpreter.

Copied from Perforce
 Change: 185089
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Gareth Rees 2014-03-30 14:26:02 +01:00
parent 0eba9c6112
commit 8c5bb6ae3c
14 changed files with 115 additions and 148 deletions

View file

@ -122,16 +122,9 @@ static size_t randomSizeAligned(size_t i)
}
static mps_pool_debug_option_s bothOptions8 = {
/* .fence_template = */ (const void *)"postpost",
/* .fence_size = */ 8,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
static mps_pool_debug_option_s bothOptions16 = {
static mps_pool_debug_option_s bothOptions = {
/* .fence_template = */ (const void *)"postpostpostpost",
/* .fence_size = */ 16,
/* .fence_size = */ MPS_PF_ALIGN,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
@ -181,9 +174,6 @@ static void testInArena(mps_arena_t arena, mps_pool_debug_option_s *options)
int main(int argc, char *argv[])
{
mps_arena_t arena;
mps_pool_debug_option_s *bothOptions;
bothOptions = MPS_PF_ALIGN == 8 ? &bothOptions8 : &bothOptions16;
testlib_init(argc, argv);
@ -200,7 +190,7 @@ int main(int argc, char *argv[])
die(mps_arena_create_k(&arena, mps_arena_class_vm(), args),
"mps_arena_create");
} MPS_ARGS_END(args);
testInArena(arena, bothOptions);
testInArena(arena, &bothOptions);
mps_arena_destroy(arena);
MPS_ARGS_BEGIN(args) {
@ -210,7 +200,7 @@ int main(int argc, char *argv[])
die(mps_arena_create_k(&arena, mps_arena_class_cl(), args),
"mps_arena_create");
} MPS_ARGS_END(args);
testInArena(arena, bothOptions);
testInArena(arena, &bothOptions);
mps_arena_destroy(arena);
printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);

View file

@ -3,7 +3,7 @@
# gc.gmk: GNUMAKEFILE FRAGMENT FOR GNU CC
#
# $Id$
# Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
# Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
#
# This file is included by platform makefiles that use the GNU CC
# compiler. It defines the compiler-specific variables that the
@ -12,11 +12,23 @@
CC = gcc
CFLAGSDEBUG = -O -g3
CFLAGSOPT = -O2 -g3
CFLAGSCOMPILER := -Wall -Wextra -Werror -Wpointer-arith \
-Wstrict-prototypes -Wmissing-prototypes \
-Winline -Waggregate-return -Wnested-externs \
-Wcast-qual -Wshadow -Wwrite-strings # -Wstrict-aliasing=2
CFLAGSCOMPILERSTRICT := -ansi -pedantic -Wshadow
CFLAGSCOMPILER := \
-pedantic \
-Waggregate-return \
-Wall \
-Wcast-qual \
-Werror \
-Wextra \
-Winline \
-Wmissing-prototypes \
-Wnested-externs \
-Wpointer-arith \
-Wshadow \
-Wstrict-aliasing=2 \
-Wstrict-prototypes \
-Wunreachable-code \
-Wwrite-strings
CFLAGSCOMPILERSTRICT := -ansi
# A different set of compiler flags for less strict compilation, for
# instance when we need to #include a third-party header file that
@ -38,7 +50,7 @@ endef
# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
# Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
# All rights reserved. This is an open source license. Contact
# Ravenbrook for commercial licensing options.
#

View file

@ -3,7 +3,7 @@
# ll.gmk: GNUMAKEFILE FRAGMENT FOR CLANG/LLVM
#
# $Id$
# Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
# Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
#
# This file is included by platform makefiles that use the Clang/LLVM
# compiler. It defines the compiler-specific variables that the
@ -12,11 +12,24 @@
CC = clang
CFLAGSDEBUG = -O -g3
CFLAGSOPT = -O2 -g3
CFLAGSCOMPILER := -Wall -Werror -Wpointer-arith \
-Wstrict-prototypes -Wmissing-prototypes \
-Winline -Waggregate-return -Wnested-externs \
-Wcast-qual -Wshadow # -Wstrict-aliasing=2
CFLAGSCOMPILERSTRICT := -pedantic -Wno-extended-offsetof
CFLAGSCOMPILER := \
-pedantic \
-Waggregate-return \
-Wall \
-Wcast-qual \
-Werror \
-Wextra \
-Winline \
-Wmissing-prototypes \
-Wnested-externs \
-Wno-extended-offsetof \
-Wpointer-arith \
-Wshadow \
-Wstrict-aliasing=2 \
-Wstrict-prototypes \
-Wunreachable-code \
-Wwrite-strings
CFLAGSCOMPILERSTRICT :=
# A different set of compiler flags for less strict compilation, for
# instance when we need to #include a third-party header file that
@ -38,7 +51,7 @@ endef
# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
# Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
# All rights reserved. This is an open source license. Contact
# Ravenbrook for commercial licensing options.
#

View file

@ -1008,9 +1008,6 @@ extern void StackProbe(Size depth);
* STATISTIC_WRITE is inserted in WriteF arguments to output the values
* of statistic fields.
*
* STATISTIC_BEGIN and STATISTIC_END can be used around a block of
* statements.
*
* .statistic.whitehot: The implementation of STATISTIC for
* non-statistical varieties passes the parameter to DISCARD to ensure
* the parameter is syntactically an expression. The parameter is
@ -1022,16 +1019,12 @@ extern void StackProbe(Size depth);
#define STATISTIC(gather) BEGIN (gather); END
#define STATISTIC_STAT(gather) BEGIN gather; END
#define STATISTIC_WRITE(format, arg) (format), (arg),
#define STATISTIC_BEGIN BEGIN
#define STATISTIC_END END
#elif defined(STATISTICS_NONE)
#define STATISTIC(gather) DISCARD(((gather), 0))
#define STATISTIC_STAT DISCARD_STAT
#define STATISTIC_WRITE(format, arg)
#define STATISTIC_BEGIN BEGIN if (0) {
#define STATISTIC_END } END
#else /* !defined(STATISTICS) && !defined(STATISTICS_NONE) */

View file

@ -125,16 +125,9 @@ static size_t fixedSize(size_t i)
}
static mps_pool_debug_option_s bothOptions8 = {
/* .fence_template = */ (const void *)"postpost",
/* .fence_size = */ 8,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
static mps_pool_debug_option_s bothOptions16 = {
static mps_pool_debug_option_s bothOptions = {
/* .fence_template = */ (const void *)"postpostpostpost",
/* .fence_size = */ 16,
/* .fence_size = */ MPS_PF_ALIGN,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
@ -177,15 +170,12 @@ static void testInArena(mps_arena_t arena, mps_pool_debug_option_s *options)
int main(int argc, char *argv[])
{
mps_arena_t arena;
mps_pool_debug_option_s *bothOptions;
bothOptions = MPS_PF_ALIGN == 8 ? &bothOptions8 : &bothOptions16;
testlib_init(argc, argv);
die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE),
"mps_arena_create");
testInArena(arena, bothOptions);
testInArena(arena, &bothOptions);
mps_arena_destroy(arena);
die(mps_arena_create(&arena, mps_arena_class_vm(), smallArenaSIZE),

View file

@ -4609,29 +4609,24 @@
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.4;
OTHER_CFLAGS = (
"-pedantic",
"-Wall",
"-Wextra",
"-Wwrite-strings",
"-Wno-extended-offsetof",
);
SDKROOT = macosx;
SYMROOT = xc;
WARNING_CFLAGS = (
"-pedantic",
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Winline",
"-Waggregate-return",
"-Wnested-externs",
"-Wcast-qual",
"-Wshadow",
"-Wall",
"-Wcast-qual",
"-Wextra",
"-Wwrite-strings",
"-Winline",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wno-extended-offsetof",
"-Wpointer-arith",
"-Wshadow",
"-Wstrict-aliasing=2",
"-Wstrict-prototypes",
"-Wunreachable-code",
"-Wwrite-strings",
);
};
name = RASH;
@ -5053,29 +5048,24 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.4;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = (
"-pedantic",
"-Wall",
"-Wextra",
"-Wwrite-strings",
"-Wno-extended-offsetof",
);
SDKROOT = macosx;
SYMROOT = xc;
WARNING_CFLAGS = (
"-pedantic",
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Winline",
"-Waggregate-return",
"-Wnested-externs",
"-Wcast-qual",
"-Wshadow",
"-Wall",
"-Wcast-qual",
"-Wextra",
"-Wwrite-strings",
"-Winline",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wno-extended-offsetof",
"-Wpointer-arith",
"-Wshadow",
"-Wstrict-aliasing=2",
"-Wstrict-prototypes",
"-Wunreachable-code",
"-Wwrite-strings",
);
};
name = Debug;
@ -5111,29 +5101,24 @@
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.4;
OTHER_CFLAGS = (
"-pedantic",
"-Wall",
"-Wextra",
"-Wwrite-strings",
"-Wno-extended-offsetof",
);
SDKROOT = macosx;
SYMROOT = xc;
WARNING_CFLAGS = (
"-pedantic",
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Wmissing-prototypes",
"-Winline",
"-Waggregate-return",
"-Wnested-externs",
"-Wcast-qual",
"-Wshadow",
"-Wall",
"-Wcast-qual",
"-Wextra",
"-Wwrite-strings",
"-Winline",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wno-extended-offsetof",
"-Wpointer-arith",
"-Wshadow",
"-Wstrict-aliasing=2",
"-Wstrict-prototypes",
"-Wunreachable-code",
"-Wwrite-strings",
);
};
name = Release;

View file

@ -2242,18 +2242,18 @@ static void AMCTraceEnd(Pool pool, Trace trace)
ti = trace->ti;
AVER(TraceIdCheck(ti));
STATISTIC_BEGIN {
Count pRetMin = 100;
PageRetStruct *pr = &amc->pageretstruct[ti];
if(pr->pRet >= pRetMin) {
EVENT21(AMCTraceEnd, ArenaEpoch(pool->arena), (EventFU)trace->why,
ArenaAlign(pool->arena), AMCLargeSegPAGES, pRetMin, pr->pCond,
pr->pRet, pr->pCS, pr->pRS, pr->sCM, pr->pCM, pr->sRM, pr->pRM,
pr->pRM1, pr->pRMrr, pr->pRMr1, pr->sCL, pr->pCL, pr->sRL,
pr->pRL, pr->pRLr);
}
*pr = pageretstruct_Zero;
} STATISTIC_END;
STATISTIC_STAT ({
Count pRetMin = 100;
PageRetStruct *pr = &amc->pageretstruct[ti];
if(pr->pRet >= pRetMin) {
EVENT21(AMCTraceEnd, ArenaEpoch(pool->arena), (EventFU)trace->why,
ArenaAlign(pool->arena), AMCLargeSegPAGES, pRetMin, pr->pCond,
pr->pRet, pr->pCS, pr->pRS, pr->sCM, pr->pCM, pr->sRM, pr->pRM,
pr->pRM1, pr->pRMrr, pr->pRMr1, pr->sCL, pr->pCL, pr->sRL,
pr->pRL, pr->pRLr);
}
*pr = pageretstruct_Zero;
});
}

View file

@ -140,41 +140,29 @@ static size_t randomSize8(size_t i)
/* testInArena -- test all the pool classes in the given arena */
static mps_pool_debug_option_s debugOptions8 = {
/* .fence_template = */ (const void *)"postpost",
/* .fence_size = */ 8,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
static mps_pool_debug_option_s debugOptions16 = {
static mps_pool_debug_option_s debugOptions = {
/* .fence_template = */ (const void *)"postpostpostpost",
/* .fence_size = */ 16,
/* .fence_size = */ MPS_PF_ALIGN,
/* .free_template = */ (const void *)"DEAD",
/* .free_size = */ 4
};
static mps_sac_classes_s classes8[4] = { {8, 1, 1}, {16, 1, 2}, {136, 9, 5},
{topClassSIZE, 9, 4} };
static mps_sac_classes_s classes16[4] = { {16, 1, 1}, {32, 1, 2}, {144, 9, 5},
{topClassSIZE, 9, 4} };
static mps_sac_classes_s classes[4] = {
{MPS_PF_ALIGN, 1, 1},
{MPS_PF_ALIGN * 2, 1, 2},
{128 + MPS_PF_ALIGN, 9, 5},
{topClassSIZE, 9, 4}
};
static void testInArena(mps_arena_t arena)
{
mps_pool_debug_option_s *debugOptions;
mps_sac_classes_s *classes;
debugOptions = MPS_PF_ALIGN == 8 ? &debugOptions8 : &debugOptions16;
classes = MPS_PF_ALIGN == 8 ? classes8 : classes16;
printf("MVFF\n\n");
die(stress(mps_class_mvff(), classCOUNT, classes, randomSize8, arena,
(size_t)65536, (size_t)32, (mps_align_t)MPS_PF_ALIGN, TRUE, TRUE, TRUE),
"stress MVFF");
printf("MV debug\n\n");
die(stress(mps_class_mv_debug(), classCOUNT, classes, randomSize8, arena,
debugOptions, (size_t)65536, (size_t)32, (size_t)65536),
&debugOptions, (size_t)65536, (size_t)32, (size_t)65536),
"stress MV debug");
printf("MV\n\n");
die(stress(mps_class_mv(), classCOUNT, classes, randomSize8, arena,

View file

@ -1,7 +1,7 @@
/* trace.c: GENERIC TRACER IMPLEMENTATION
*
* $Id$
* Copyright (c) 2001-2013 Ravenbrook Limited.
* Copyright (c) 2001-2014 Ravenbrook Limited.
* See end of file for license.
* Portions copyright (C) 2002 Global Graphics Software.
*
@ -1641,11 +1641,12 @@ Res TraceStart(Trace trace, double mortality, double finishingTime)
} while (SegNext(&seg, arena, seg));
}
STATISTIC_BEGIN {
STATISTIC_STAT ({
/* @@ */
/* Iterate over all chains, all GenDescs within a chain, */
/* (and all PoolGens within a GenDesc). */
Ring node, nextNode;
Ring node;
Ring nextNode;
Index i;
RING_FOR(node, &arena->chainRing, nextNode) {
@ -1658,7 +1659,7 @@ Res TraceStart(Trace trace, double mortality, double finishingTime)
/* Now do topgen GenDesc (and all PoolGens within it). */
TraceStartPoolGen(NULL, &arena->topGen, TRUE, 0);
} STATISTIC_END;
});
res = RootsIterate(ArenaGlobals(arena), rootGrey, (void *)trace);
AVER(res == ResOK);
@ -1900,7 +1901,7 @@ failStart:
/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2013 Ravenbrook Limited
* Copyright (C) 2001-2014 Ravenbrook Limited
* <http://www.ravenbrook.com/>.
* All rights reserved. This is an open source license. Contact
* Ravenbrook for commercial licensing options.

View file

@ -442,6 +442,9 @@ static void testscriptA(const char *script)
*
* TIMCA_remote returns a Bool, true for let "ControlAlloc succeed".
*/
#ifdef TEST_CONTROLALLOC_FAILURE
static const char *TIMCA_str = "";
static int TIMCA_done = 0;
static void TIMCA_setup(const char *string)
@ -481,6 +484,8 @@ Bool TIMCA_remote(void)
return succeed;
}
#endif /* TEST_CONTROLALLOC_FAILURE */
/* main -- runs various test scripts
*
@ -535,7 +540,8 @@ int main(int argc, char *argv[])
*
* See <design/message-gc#lifecycle>.
*/
if(0) {
#if TEST_CONTROLALLOC_FAILURE
{
/* ArenaCreate unable to pre-allocate: THESE SHOULD FAIL */
/* manually edit if(0) -> if(1) to test these */
if(0) {
@ -562,6 +568,7 @@ int main(int argc, char *argv[])
TIMCA_setup(""); /* must reset it! */
}
#endif
printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
return 0;

View file

@ -2011,8 +2011,6 @@ static obj_t entry_do(obj_t env, obj_t op_env, obj_t operator, obj_t operands)
return result;
}
}
error("%s: unimplemented", operator->operator.name);
return obj_error;
}
@ -4007,7 +4005,6 @@ static mps_res_t obj_scan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit)
assert(0);
fprintf(stderr, "Unexpected object on the heap\n");
abort();
return MPS_RES_FAIL;
}
}
} MPS_SCAN_END(ss);
@ -4078,7 +4075,6 @@ static mps_addr_t obj_skip(mps_addr_t base)
assert(0);
fprintf(stderr, "Unexpected object on the heap\n");
abort();
return NULL;
}
return base;
}

View file

@ -1,6 +1,6 @@
/* scheme.c -- SCHEME INTERPRETER EXAMPLE FOR THE MEMORY POOL SYSTEM
*
* Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
* Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
*
* TO DO
* - unbounded integers, other number types.
@ -1728,8 +1728,6 @@ static obj_t entry_do(obj_t env, obj_t op_env, obj_t operator, obj_t operands)
return result;
}
}
error("%s: unimplemented", operator->operator.name);
return obj_error;
}
@ -3638,7 +3636,7 @@ int main(int argc, char *argv[])
/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
* Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
* All rights reserved. This is an open source license. Contact
* Ravenbrook for commercial licensing options.
*

View file

@ -1,6 +1,6 @@
/* scheme.c -- SCHEME INTERPRETER EXAMPLE FOR THE MEMORY POOL SYSTEM
*
* Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
* Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
*
* TO DO
* - unbounded integers, other number types.
@ -1728,8 +1728,6 @@ static obj_t entry_do(obj_t env, obj_t op_env, obj_t operator, obj_t operands)
return result;
}
}
error("%s: unimplemented", operator->operator.name);
return obj_error;
}
@ -3635,7 +3633,7 @@ int main(int argc, char *argv[])
/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
* Copyright (C) 2001-2014 Ravenbrook Limited <http://www.ravenbrook.com/>.
* All rights reserved. This is an open source license. Contact
* Ravenbrook for commercial licensing options.
*

View file

@ -2037,8 +2037,6 @@ static obj_t entry_do(obj_t env, obj_t op_env, obj_t operator, obj_t operands)
return result;
}
}
error("%s: unimplemented", operator->operator.name);
return obj_error;
}
@ -3994,7 +3992,6 @@ static mps_res_t obj_scan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit)
assert(0);
fprintf(stderr, "Unexpected object on the heap\n");
abort();
return MPS_RES_FAIL;
}
}
} MPS_SCAN_END(ss);
@ -4071,7 +4068,6 @@ static mps_addr_t obj_skip(mps_addr_t base)
assert(0);
fprintf(stderr, "Unexpected object on the heap\n");
abort();
return NULL;
}
return base;
}