From 01bb687ddc7dc77a63e14954f8fd27bf66232381 Mon Sep 17 00:00:00 2001 From: Brad King <brad.king@kitware.com> Date: Fri, 2 Jul 2010 13:57:19 -0400 Subject: [PATCH] KWSys: Avoid Clang optimizer bug in testProcess-[45] Clang's optimizer, as of clang version 2.8 (trunk 107463), produces the undefined instruction 'ud2' for the code "*(int*)0=0" on OS X x86_64. It causes our crash tests to fail because the child process exits with an invalid instruction instead of a segmentation fault. Work around the bug by using "*(int*)1=0" in this case. --- kwsysDateStamp.cmake | 4 ++-- testProcess.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kwsysDateStamp.cmake b/kwsysDateStamp.cmake index b70c005..52a4b4a 100644 --- a/kwsysDateStamp.cmake +++ b/kwsysDateStamp.cmake @@ -15,7 +15,7 @@ SET(KWSYS_DATE_STAMP_YEAR 2010) # KWSys version date month component. Format is MM. -SET(KWSYS_DATE_STAMP_MONTH 06) +SET(KWSYS_DATE_STAMP_MONTH 07) # KWSys version date day component. Format is DD. -SET(KWSYS_DATE_STAMP_DAY 30) +SET(KWSYS_DATE_STAMP_DAY 02) diff --git a/testProcess.c b/testProcess.c index 0060c4d..6044917 100644 --- a/testProcess.c +++ b/testProcess.c @@ -94,7 +94,12 @@ 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. */ +#else *(int*)0 = 0; +#endif fprintf(stdout, "Output after crash on stdout from crash test.\n"); fprintf(stderr, "Output after crash on stderr from crash test.\n"); return 0; -- GitLab