Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix finite-math-only lgamma functions signgam setting (bug 19211).
The lgamma inline functions in bits/math-finite.h do not set signgam if __USE_ISOC99, even when other feature test macros mean a standard such as XSI POSIX is selected for which it should be set. (This is essentially the opposite issue to bug 15421, the out-of-line versions setting signgam even when they shouldn't.) This patch fixes those functions to use __USE_MISC || __USE_XOPEN as the condition for when to set signgam, since it's the condition for when math.h declares signgam. The legacy gamma* names are only declared at all if __USE_MISC || __USE_XOPEN, so they just set signgam unconditionally. Tests for certain standards or not using _GNU_SOURCE cannot use test-skeleton.c (this is a known issue noted on the wiki todo list). Thus, the new tests that signgam remains not set in ISO C modes do not use test-skeleton.c. They also define _ISOMAC to avoid running into declarations in the internal include/ headers that only work in _GNU_SOURCE mode. Tested for x86_64 and x86. [BZ #19211] * math/bits/math-finite.h (lgamma): Set signgam if [__USE_MISC || __USE_XOPEN], not if [!__USE_ISOC99]. (lgammaf): Likewise. (lgammal): Likewise. (gamma): Set signgam unconditionally, not if [!__USE_ISOC99]. (gammaf): Likewise. (gammal): Likewise. * math/test-signgam-finite-c11.c: New file. * math/test-signgam-finite-c99.c: Likewise. * math/test-signgam-finite.c: Likewise. * math/Makefile (tests): Add test-signgam-finite, test-signgam-finite-c99 and test-signgam-finite-c11. (CFLAGS-test-signgam-finite.c): New variable. (CFLAGS-test-signgam-finite-c99.c): Likewise. (CFLAGS-test-signgam-finite-c11.c): Likewise.
- Loading branch information
Joseph Myers
committed
Nov 5, 2015
1 parent
f248238
commit 939fdd1
Showing
7 changed files
with
164 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "test-signgam-finite-c99.c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Test lgamma functions do not set signgam for -ffinite-math-only for ISO C. | ||
Copyright (C) 2015 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, see | ||
<http://www.gnu.org/licenses/>. */ | ||
|
||
#undef _LIBC | ||
#undef _GNU_SOURCE | ||
#define _ISOMAC | ||
|
||
#include <math.h> | ||
#include <stdio.h> | ||
|
||
int signgam; | ||
|
||
#define RUN_TESTS(FUNC, TYPE) \ | ||
do \ | ||
{ \ | ||
volatile TYPE a, b, c __attribute__ ((unused)); \ | ||
a = 0.5; \ | ||
b = -0.5; \ | ||
signgam = 123; \ | ||
c = FUNC (a); \ | ||
if (signgam == 123) \ | ||
puts ("PASS: " #FUNC " (0.5) setting signgam"); \ | ||
else \ | ||
{ \ | ||
puts ("FAIL: " #FUNC " (0.5) setting signgam"); \ | ||
result = 1; \ | ||
} \ | ||
signgam = 123; \ | ||
c = FUNC (b); \ | ||
if (signgam == 123) \ | ||
puts ("PASS: " #FUNC " (0.5) setting signgam"); \ | ||
else \ | ||
{ \ | ||
puts ("FAIL: " #FUNC " (0.5) setting signgam"); \ | ||
result = 1; \ | ||
} \ | ||
} \ | ||
while (0) | ||
|
||
int | ||
main (void) | ||
{ | ||
int result = 0; | ||
RUN_TESTS (lgammaf, float); | ||
RUN_TESTS (lgamma, double); | ||
#ifndef NO_LONG_DOUBLE | ||
RUN_TESTS (lgammal, long double); | ||
#endif | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Test lgamma functions set signgam for -ffinite-math-only (bug 19211). | ||
Copyright (C) 2015 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, see | ||
<http://www.gnu.org/licenses/>. */ | ||
|
||
#include <math.h> | ||
#include <stdio.h> | ||
|
||
#define RUN_TESTS(FUNC, TYPE) \ | ||
do \ | ||
{ \ | ||
volatile TYPE a, b, c __attribute__ ((unused)); \ | ||
a = 0.5; \ | ||
b = -0.5; \ | ||
signgam = 123; \ | ||
c = FUNC (a); \ | ||
if (signgam == 1) \ | ||
puts ("PASS: " #FUNC " (0.5) setting signgam"); \ | ||
else \ | ||
{ \ | ||
puts ("FAIL: " #FUNC " (0.5) setting signgam"); \ | ||
result = 1; \ | ||
} \ | ||
signgam = 123; \ | ||
c = FUNC (b); \ | ||
if (signgam == -1) \ | ||
puts ("PASS: " #FUNC " (0.5) setting signgam"); \ | ||
else \ | ||
{ \ | ||
puts ("FAIL: " #FUNC " (0.5) setting signgam"); \ | ||
result = 1; \ | ||
} \ | ||
} \ | ||
while (0) | ||
|
||
static int | ||
do_test (void) | ||
{ | ||
int result = 0; | ||
RUN_TESTS (lgammaf, float); | ||
RUN_TESTS (gammaf, float); | ||
RUN_TESTS (lgamma, double); | ||
RUN_TESTS (gamma, double); | ||
#ifndef NO_LONG_DOUBLE | ||
RUN_TESTS (lgammal, long double); | ||
RUN_TESTS (gammal, long double); | ||
#endif | ||
return result; | ||
} | ||
|
||
#define TEST_FUNCTION do_test () | ||
#include "../test-skeleton.c" |