From 70154efef86c7025435b15c52a8a1a5b47067835 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 9 Jul 2010 10:30:18 -0400 Subject: [PATCH] KWSys: Avoid undefined behavior in Process crash tests Clang is smart enough to recognize that "*(int*)0=0" invokes undefined behavior, warns, and produces an "undefined instruction". The message in commit "Avoid Clang optimizer bug in testProcess-[45]" (2010-07-02) is incorrect; this is not a Clang bug. It really is undefined behavior. Use "*(int*)1=0" to produce a crash instead. --- Source/kwsys/testProcess.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c index 60449175b..877002a14 100644 --- a/Source/kwsys/testProcess.c +++ b/Source/kwsys/testProcess.c @@ -94,9 +94,8 @@ int test4(int argc, const char* argv[]) fprintf(stderr, "Output before crash on stderr from crash test.\n"); fflush(stdout); fflush(stderr); -#if defined(__APPLE__) && defined(__x86_64__) && defined(__OPTIMIZE__) \ - && defined(__clang__) - *(int*)1 = 0; /* Clang's optimizer produces bad code for 0-ptr. */ +#if defined(__clang__) + *(int*)1 = 0; /* Clang warns about 0-ptr; undefined behavior. */ #else *(int*)0 = 0; #endif