- Package:
- gcc-defaults
- Source:
- gcc-defaults
- Submitter:
- Matthew Vernon
- Date:
- 2010-05-30 17:12:16 UTC
- Severity:
- important
Hi,
C99 requires that code that tests floating-point state flags (or frobs
other bits of the floating-point environment) calls #pragma STDC
FENV_ACCESS ON:
"If part of an application tests floating-point status flags, sets
floating-point control modes, or runs under non-default mode settings,
but was translated with the state for the FENV_ACCESS pragma off, the
behavior is undefined." (7.6.1.2)
Yet, if you do this in gcc with -Wall turned on, you get a warning
message:
matthew@b144-mcv1-mlt:/tmp$ cat test.c
#include <stdio.h>
#include <fenv.h>
int main(void)
{
#pragma STDC FENV_ACCESS ON
if(feclearexcept(FE_ALL_EXCEPT))
printf("feclearexcept failed\n");
else printf("feclearexcept succeeded\n");
return 0;
}
matthew@b144-mcv1-mlt:/tmp$ gcc -std=gnu99 -Wall test.c -lm
test.c: In function ‘main’:
test.c:6: warning: ignoring #pragma STDC FENV_ACCESS
matthew@b144-mcv1-mlt:/tmp$ ./a.out
feclearexcept succeeded
matthew@b144-mcv1-mlt:/tmp$
It's obviously buggy to emit a warning on standards-mandated behaviour!
I know you can turn this warning off with -Wno-unknown-pragmas, but
that's not something you want to be doing in production code.
Regards,
Matthew
gcc does not stat full C99 compilance. Please show the part of the standard. A compiler may produce warnings without reason. Bastian
Hi, Bastian Blank wrote: Was the section I quoted in my original bug report not sufficient? Paragraph 7.6.1.2 of C99 says [again]: "If part of a program tests floating-point status flags, sets floating-point control modes, or runs under non-default mode settings, but was translated with the state for the FENV_ACCESS pragma "off", *the behaviour is undefined*." [emphasis mine] These are things that many correct programs will want to do. For example, SuSv3 has this to say about pow(): "An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred."[1] Gcc as-is, will encourage (quite strongly, since may people will compile with -Wall, +/- -Werror) users to write code that calls feclearexcept() and suchlike without using #pragma STDC FENV_ACCESS ON first. This is undefined behaviour, according to C99! It seems clear to me that this is a bug in gcc. Regards, Matthew [1] http://www.opengroup.org/onlinepubs/009695399/functions/pow.html
forwarded 503204 http://gcc.gnu.org/PR20785 tag 503204 + upstream reassign 503204 gcc-defaults thanks reassigning to gcc-defaults, same in 4.5 and trunk.
forwarded 503204 http://gcc.gnu.org/PR20785 tag 503204 + upstream reassign 503204 gcc-defaults thanks reassigning to gcc-defaults, same in 4.5 and trunk.