summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorErik de Castro Lopo <erik.decastrolopo@ambiata.com>2017-04-05 05:53:46 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2017-04-05 05:53:47 +1000
commit7e340c2bbf4a56959bd1e95cdd1cfdb2b7e537c2 (patch)
tree0f330ad348b5100f1a21312e7c91e43966789ec8 /rts
parent5e968f9261b798222a845ef38a54621b45013678 (diff)
downloadhaskell-7e340c2bbf4a56959bd1e95cdd1cfdb2b7e537c2.tar.gz
Enable new warning for fragile/incorrect CPP #if usage
The C code in the RTS now gets built with `-Wundef` and the Haskell code (stages 1 and 2 only) with `-Wcpp-undef`. We now get warnings whereever `#if` is used on undefined identifiers. Test Plan: Validate on Linux and Windows Reviewers: austin, angerman, simonmar, bgamari, Phyx Reviewed By: bgamari Subscribers: thomie, snowleopard Differential Revision: https://phabricator.haskell.org/D3278
Diffstat (limited to 'rts')
-rw-r--r--rts/LinkerInternals.h11
-rw-r--r--rts/OldARMAtomic.c2
-rw-r--r--rts/PrimOps.cmm4
-rw-r--r--rts/RtsUtils.c4
-rw-r--r--rts/Schedule.c16
-rw-r--r--rts/Threads.c2
-rw-r--r--rts/ghc.mk5
-rw-r--r--rts/linker/MachO.c10
-rw-r--r--rts/posix/GetTime.c2
-rw-r--r--rts/posix/OSMem.c8
-rw-r--r--rts/posix/OSThreads.c2
-rw-r--r--rts/posix/itimer/Pthread.c6
-rw-r--r--rts/sm/CNF.c2
-rw-r--r--rts/sm/GCUtils.c2
-rw-r--r--rts/sm/GCUtils.h2
-rw-r--r--rts/sm/MBlock.c2
16 files changed, 43 insertions, 37 deletions
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
index 16fbab2b29..a04db77b92 100644
--- a/rts/LinkerInternals.h
+++ b/rts/LinkerInternals.h
@@ -91,7 +91,8 @@ typedef struct ForeignExportStablePtr_ {
struct ForeignExportStablePtr_ *next;
} ForeignExportStablePtr;
-#if powerpc_HOST_ARCH || x86_64_HOST_ARCH || arm_HOST_ARCH
+#if defined(powerpc_HOST_ARCH) || defined(x86_64_HOST_ARCH) \
+ || defined(arm_HOST_ARCH)
/* ios currently uses adjacent got tables, and no symbol extras */
#if !defined(ios_HOST_OS)
#define NEED_SYMBOL_EXTRAS 1
@@ -102,17 +103,17 @@ typedef struct ForeignExportStablePtr_ {
* address relocations on the PowerPC, x86_64 and ARM.
*/
typedef struct {
-#ifdef powerpc_HOST_ARCH
+#if defined(powerpc_HOST_ARCH)
struct {
short lis_r12, hi_addr;
short ori_r12_r12, lo_addr;
long mtctr_r12;
long bctr;
} jumpIsland;
-#elif x86_64_HOST_ARCH
+#elif defined(x86_64_HOST_ARCH)
uint64_t addr;
uint8_t jumpIsland[6];
-#elif arm_HOST_ARCH
+#elif defined(arm_HOST_ARCH)
uint8_t jumpIsland[16];
#endif
} SymbolExtra;
@@ -283,7 +284,7 @@ ObjectCode* mkOc( pathchar *path, char *image, int imageSize,
int misalignment
);
-#if defined (mingw32_HOST_OS)
+#if defined(mingw32_HOST_OS)
/* We use myindex to calculate array addresses, rather than
simply doing the normal subscript thing. That's because
some of the above structs have sizes which are not
diff --git a/rts/OldARMAtomic.c b/rts/OldARMAtomic.c
index 3c60e6d669..e76f4c6354 100644
--- a/rts/OldARMAtomic.c
+++ b/rts/OldARMAtomic.c
@@ -20,7 +20,7 @@
#include <sched.h>
#endif
-#if arm_HOST_ARCH && defined(arm_HOST_ARCH_PRE_ARMv6)
+#if defined(arm_HOST_ARCH) && defined(arm_HOST_ARCH_PRE_ARMv6)
static volatile int atomic_spin = 0;
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index 4baf63a8f7..37eee439ac 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -561,7 +561,7 @@ stg_atomicModifyMutVarzh ( gcptr mv, gcptr f )
r = [stg_sel_1 z] (max (HS + 1) MIN_UPD_SIZE)
*/
-#if MIN_UPD_SIZE > 1
+#if defined(MIN_UPD_SIZE) && MIN_UPD_SIZE > 1
#define THUNK_1_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE))
#define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),WDS(MIN_UPD_SIZE-1))
#else
@@ -569,7 +569,7 @@ stg_atomicModifyMutVarzh ( gcptr mv, gcptr f )
#define TICK_ALLOC_THUNK_1() TICK_ALLOC_UP_THK(WDS(1),0)
#endif
-#if MIN_UPD_SIZE > 2
+#if defined(MIN_UPD_SIZE) && MIN_UPD_SIZE > 2
#define THUNK_2_SIZE (SIZEOF_StgThunkHeader + WDS(MIN_UPD_SIZE))
#define TICK_ALLOC_THUNK_2() TICK_ALLOC_UP_THK(WDS(2),WDS(MIN_UPD_SIZE-2))
#else
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c
index 85f951addd..996d28ac4c 100644
--- a/rts/RtsUtils.c
+++ b/rts/RtsUtils.c
@@ -22,7 +22,7 @@
/* HACK: On Mac OS X 10.4 (at least), time.h doesn't declare ctime_r with
* _POSIX_C_SOURCE. If this is the case, we declare it ourselves.
*/
-#if HAVE_CTIME_R && !HAVE_DECL_CTIME_R
+#if defined(HAVE_CTIME_R) && !HAVE_DECL_CTIME_R
extern char *ctime_r(const time_t *, char *);
#endif
@@ -164,7 +164,7 @@ time_str(void)
if (now == 0) {
time(&now);
-#if HAVE_CTIME_R
+#if defined(HAVE_CTIME_R)
ctime_r(&now, nowstr);
#else
strcpy(nowstr, ctime(&now));
diff --git a/rts/Schedule.c b/rts/Schedule.c
index b77e7a21ef..296461b38d 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -411,7 +411,7 @@ run_thread:
prev_what_next = t->what_next;
errno = t->saved_errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
SetLastError(t->saved_winerror);
#endif
@@ -490,7 +490,7 @@ run_thread:
// XXX: possibly bogus for SMP because this thread might already
// be running again, see code below.
t->saved_errno = errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
// Similarly for Windows error code
t->saved_winerror = GetLastError();
#endif
@@ -2374,12 +2374,12 @@ suspendThread (StgRegTable *reg, bool interruptible)
int saved_errno;
StgTSO *tso;
Task *task;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
StgWord32 saved_winerror;
#endif
saved_errno = errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
saved_winerror = GetLastError();
#endif
@@ -2419,7 +2419,7 @@ suspendThread (StgRegTable *reg, bool interruptible)
RELEASE_LOCK(&cap->lock);
errno = saved_errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
SetLastError(saved_winerror);
#endif
return task;
@@ -2433,12 +2433,12 @@ resumeThread (void *task_)
Capability *cap;
Task *task = task_;
int saved_errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
StgWord32 saved_winerror;
#endif
saved_errno = errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
saved_winerror = GetLastError();
#endif
@@ -2475,7 +2475,7 @@ resumeThread (void *task_)
cap->r.rCurrentTSO = tso;
cap->in_haskell = true;
errno = saved_errno;
-#if mingw32_HOST_OS
+#ifdef mingw32_HOST_OS
SetLastError(saved_winerror);
#endif
diff --git a/rts/Threads.c b/rts/Threads.c
index f5eb9d360c..9cfd36a7c9 100644
--- a/rts/Threads.c
+++ b/rts/Threads.c
@@ -826,7 +826,7 @@ loop:
* Debugging: why is a thread blocked
* ------------------------------------------------------------------------- */
-#if DEBUG
+#ifdef DEBUG
void
printThreadBlockage(StgTSO *tso)
{
diff --git a/rts/ghc.mk b/rts/ghc.mk
index b756d942ca..e24e199598 100644
--- a/rts/ghc.mk
+++ b/rts/ghc.mk
@@ -267,7 +267,10 @@ WARNING_OPTS += -Waggregate-return
WARNING_OPTS += -Wpointer-arith
WARNING_OPTS += -Wmissing-noreturn
WARNING_OPTS += -Wnested-externs
-WARNING_OPTS += -Wredundant-decls
+WARNING_OPTS += -Wredundant-decls
+ifeq "$(GccLT46)" "NO"
+WARNING_OPTS += -Wundef
+endif
# These ones are hard to avoid:
#WARNING_OPTS += -Wconversion
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 16b712a804..a7c9189250 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -248,7 +248,8 @@ ocVerifyImage_MachO(ObjectCode * oc)
IF_DEBUG(linker, debugBelch("ocVerifyImage_MachO: start\n"));
-#if x86_64_HOST_ARCH || powerpc64_HOST_ARCH || aarch64_HOST_ARCH
+#if defined(x86_64_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
+ || defined(aarch64_HOST_ARCH)
if(header->magic != MH_MAGIC_64) {
errorBelch("Could not load image %s: bad magic!\n"
" Expected %08x (64bit), got %08x%s\n",
@@ -281,7 +282,7 @@ resolveImports(
IF_DEBUG(linker, debugBelch("resolveImports: start\n"));
-#if i386_HOST_ARCH
+#if defined(i386_HOST_ARCH)
int isJumpTable = 0;
if (strcmp(sect->sectname,"__jump_table") == 0) {
@@ -319,7 +320,7 @@ resolveImports(
}
ASSERT(addr);
-#if i386_HOST_ARCH
+#if defined(i386_HOST_ARCH)
if (isJumpTable) {
checkProddableBlock(oc,oc->image + sect->offset + i*itemSize, 5);
@@ -1922,7 +1923,8 @@ machoGetMisalignment( FILE * f )
}
fseek(f, -sizeof(header), SEEK_CUR);
-#if x86_64_HOST_ARCH || powerpc64_HOST_ARCH || aarch64_HOST_ARCH
+#if defined(x86_64_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
+ || defined(aarch64_HOST_ARCH)
if(header.magic != MH_MAGIC_64) {
barf("Bad magic. Expected: %08x, got: %08x.",
MH_MAGIC_64, header.magic);
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index 4d25795948..5be9c8e350 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -190,7 +190,7 @@ void getUnixEpochTime(StgWord64 *sec, StgWord32 *nsec)
W_
getPageFaults(void)
{
-#if !defined(HAVE_GETRUSAGE) || haiku_HOST_OS
+#if !defined(HAVE_GETRUSAGE) || defined(haiku_HOST_OS)
return 0;
#else
struct rusage t;
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index dcf734f19d..48b154fa11 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -39,7 +39,7 @@
#include <errno.h>
-#if darwin_HOST_OS || ios_HOST_OS
+#if defined(darwin_HOST_OS) || defined(ios_HOST_OS)
#include <mach/mach.h>
#include <mach/vm_map.h>
#include <sys/sysctl.h>
@@ -114,7 +114,7 @@ my_mmap (void *addr, W_ size, int operation)
{
void *ret;
-#if darwin_HOST_OS
+#ifdef darwin_HOST_OS
// Without MAP_FIXED, Apple's mmap ignores addr.
// With MAP_FIXED, it overwrites already mapped regions, whic
// mmap(0, ... MAP_FIXED ...) is worst of all: It unmaps the program text
@@ -170,9 +170,9 @@ my_mmap (void *addr, W_ size, int operation)
else
flags = 0;
-#if hpux_HOST_OS
+#ifdef hpux_HOST_OS
ret = mmap(addr, size, prot, flags | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-#elif linux_HOST_OS
+#elif defined(linux_HOST_OS)
ret = mmap(addr, size, prot, flags | MAP_ANON | MAP_PRIVATE, -1, 0);
if (ret == (void *)-1 && errno == EPERM) {
// Linux may return EPERM if it tried to give us
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 45f394208f..465c8675a3 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -137,7 +137,7 @@ createOSThread (OSThreadId* pId, char *name STG_UNUSED,
int result = pthread_create(pId, NULL, (void *(*)(void *))startProc, param);
if (!result) {
pthread_detach(*pId);
-#if HAVE_PTHREAD_SETNAME_NP
+#ifdef HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(*pId, name);
#endif
}
diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index 3b31fe4103..5c708ecf4d 100644
--- a/rts/posix/itimer/Pthread.c
+++ b/rts/posix/itimer/Pthread.c
@@ -65,7 +65,7 @@
#include <unistd.h>
#include <fcntl.h>
-#if HAVE_SYS_TIMERFD_H
+#ifdef HAVE_SYS_TIMERFD_H
#include <sys/timerfd.h>
#define USE_TIMERFD_FOR_ITIMER 1
#else
@@ -101,7 +101,7 @@ static void *itimer_thread_func(void *_handle_tick)
uint64_t nticks;
int timerfd = -1;
-#if USE_TIMERFD_FOR_ITIMER
+#if defined(USE_TIMERFD_FOR_ITIMER) && USE_TIMERFD_FOR_ITIMER
struct itimerspec it;
it.it_value.tv_sec = TimeToSeconds(itimer_interval);
it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000;
@@ -169,7 +169,7 @@ initTicker (Time interval, TickProc handle_tick)
* to the thread we create so we can later join to it if requested
*/
if (! pthread_create(&thread, NULL, itimer_thread_func, (void*)handle_tick)) {
-#if HAVE_PTHREAD_SETNAME_NP
+#ifdef HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(thread, "ghc_ticker");
#endif
} else {
diff --git a/rts/sm/CNF.c b/rts/sm/CNF.c
index 624dba30b2..af90718b4f 100644
--- a/rts/sm/CNF.c
+++ b/rts/sm/CNF.c
@@ -1170,7 +1170,7 @@ compactFixupPointers(StgCompactNFData *str,
dbl_link_onto(bd, &g0->compact_objects);
RELEASE_SM_LOCK;
-#if DEBUG
+#ifdef DEBUG
if (root)
verify_consistency_loop(str);
#endif
diff --git a/rts/sm/GCUtils.c b/rts/sm/GCUtils.c
index 9fda2fe070..3717faebed 100644
--- a/rts/sm/GCUtils.c
+++ b/rts/sm/GCUtils.c
@@ -346,7 +346,7 @@ alloc_todo_block (gen_workspace *ws, uint32_t size)
* Debugging
* -------------------------------------------------------------------------- */
-#if DEBUG
+#ifdef DEBUG
void
printMutableList(bdescr *bd)
{
diff --git a/rts/sm/GCUtils.h b/rts/sm/GCUtils.h
index 3092262af6..3ea762376a 100644
--- a/rts/sm/GCUtils.h
+++ b/rts/sm/GCUtils.h
@@ -52,7 +52,7 @@ isPartiallyFull(bdescr *bd)
}
-#if DEBUG
+#ifdef DEBUG
void printMutableList (bdescr *bd);
#endif
diff --git a/rts/sm/MBlock.c b/rts/sm/MBlock.c
index f6640d173c..833dd8c7c2 100644
--- a/rts/sm/MBlock.c
+++ b/rts/sm/MBlock.c
@@ -657,7 +657,7 @@ initMBlocks(void)
#ifdef USE_LARGE_ADDRESS_SPACE
{
W_ size;
-#if aarch64_HOST_ARCH
+#ifdef aarch64_HOST_ARCH
size = (W_)1 << 38; // 1/4 TByte
#else
size = (W_)1 << 40; // 1 TByte