Module Name: src Committed By: rin Date: Fri Aug 4 03:31:13 UTC 2023
Modified Files: src/tests/lib/libc/gen: t_siginfo.c Log Message: t_siginfo:sigfpe_int: Adjust for GCC12 Do not use constant 1 as numerator to raise integer division by zero. GCC >= 12 optimizes (1 / i) into (abs(i) == 1 ? i : 0), even for -O0. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/tests/lib/libc/gen/t_siginfo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/gen/t_siginfo.c diff -u src/tests/lib/libc/gen/t_siginfo.c:1.48 src/tests/lib/libc/gen/t_siginfo.c:1.49 --- src/tests/lib/libc/gen/t_siginfo.c:1.48 Sun May 7 12:41:49 2023 +++ src/tests/lib/libc/gen/t_siginfo.c Fri Aug 4 03:31:13 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: t_siginfo.c,v 1.48 2023/05/07 12:41:49 skrll Exp $ */ +/* $NetBSD: t_siginfo.c,v 1.49 2023/08/04 03:31:13 rin Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -365,7 +365,6 @@ ATF_TC_HEAD(sigfpe_int, tc) ATF_TC_BODY(sigfpe_int, tc) { struct sigaction sa; - long l = strtol("0", NULL, 10); #if defined(__aarch64__) || defined(__powerpc__) || defined(__sh3__) atf_tc_skip("Integer division by zero doesn't trap"); @@ -380,7 +379,13 @@ ATF_TC_BODY(sigfpe_int, tc) #elif defined(_FLOAT_IEEE754) fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP); #endif - printf("%ld\n", 1 / l); + /* + * Do not use constant 1 here. GCC >= 12 optimizes + * (1 / i) to (abs(i) == 1 ? i : 0), even for -O0. + */ + long unity = strtol("1", NULL, 10), + zero = strtol("0", NULL, 10); + printf("%ld\n", unity / zero); } if (intdiv_signalled == 0) atf_tc_fail("FPE signal handler was not invoked");