Bug 90326 - Using any precompiled header breaks definition of FLT_MAX
Summary: Using any precompiled header breaks definition of FLT_MAX
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: pch (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-03 09:44 UTC by Alex Smith
Modified: 2019-08-30 12:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-05-09 00:00:00


Attachments
gcc10-pr90326.patch (968 bytes, patch)
2019-05-09 13:27 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Smith 2019-05-03 09:44:22 UTC
With Fedora 30's GCC 9.0.1 (gcc (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10)), including any precompiled header will result in FLT_MAX being defined to 0, rather than the correct value.

Reproduction test case:

10:40:54 ~ $ cat test.cpp
#include <float.h>
#include <stdio.h>
int main()
{
	float f = FLT_MAX;
	printf("%f\n", f);
	return 0;
}
10:40:56 ~ $ cat test.h
#define TEST 1
10:40:58 ~ $ g++ -o test test.cpp
10:41:08 ~ $ ./test
340282346638528859811704183484516925440.000000
10:41:10 ~ $ g++ -o test test.cpp -include test.h
10:41:16 ~ $ ./test
340282346638528859811704183484516925440.000000
10:41:17 ~ $ g++ -x c++-header -c test.h -o test.h.gch
10:41:28 ~ $ g++ -o test test.cpp -include test.h
10:41:32 ~ $ ./test
0.000000

I'm unsure if any other definitions are affected but FLT_MAX is the one that was most obviously broken to me as the incorrect value causes us a ton of issues.

GCC 8.3.0 on Arch Linux is not affected.
Comment 1 Jakub Jelinek 2019-05-03 10:24:23 UTC
Can't reproduce (with Fedora gcc 9.0.1-0.16.fc31).
Comment 2 Alex Smith 2019-05-03 15:26:38 UTC
It still repros for me on 9.0.1-0.16.fc31.

Slightly reduced test case:

$ cat test.h
#define TEST 1
$ cat test.cpp
#include <stdio.h>
static_assert(__FLT_MAX__ > 0);
int main() { return 0; }
$ g++ -o test test.cpp -include test.h
$ g++ -x c++-header -c test.h -o test.h.gch
$ g++ -o test test.cpp -include test.h
test.cpp:2:27: error: static assertion failed
    2 | static_assert(__FLT_MAX__ > 0);

Note __FLT_MAX__ is failing as well as FLT_MAX.

However, if I remove "#include <stdio.h>", it compiles successfully.
Comment 3 Alex Smith 2019-05-09 08:33:45 UTC
Still reproduces on 9.1.1-1.fc30.
Comment 4 Jakub Jelinek 2019-05-09 13:27:25 UTC
Created attachment 46325 [details]
gcc10-pr90326.patch

Untested fix.
Comment 5 Jakub Jelinek 2019-05-10 07:40:17 UTC
Author: jakub
Date: Fri May 10 07:39:46 2019
New Revision: 271055

URL: https://gcc.gnu.org/viewcvs?rev=271055&root=gcc&view=rev
Log:
	PR pch/90326
cp/
	* config-lang.in (gtfiles): Remove c-family/c-lex.c, add
	c-family/c-cppbuiltin.c.
objc/
	* config-lang.in (gtfiles): Add c-family/c-format.c.
objcp/
	* config-lang.in (gtfiles): Don't add c-family/c-cppbuiltin.c.
testsuite/
	* g++.dg/pch/pr90326.C: New test.
	* g++.dg/pch/pr90326.Hs: New file.

Added:
    trunk/gcc/testsuite/g++.dg/pch/pr90326.C
    trunk/gcc/testsuite/g++.dg/pch/pr90326.Hs
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/config-lang.in
    trunk/gcc/objc/ChangeLog
    trunk/gcc/objc/config-lang.in
    trunk/gcc/objcp/ChangeLog
    trunk/gcc/objcp/config-lang.in
    trunk/gcc/testsuite/ChangeLog
Comment 6 Alex Smith 2019-05-11 07:29:30 UTC
Confirmed that fixes it (built and test 9.1.0 from source without/with that patch applied). Thanks!
Comment 7 Jakub Jelinek 2019-05-17 19:50:26 UTC
Author: jakub
Date: Fri May 17 19:49:54 2019
New Revision: 271350

URL: https://gcc.gnu.org/viewcvs?rev=271350&root=gcc&view=rev
Log:
	Backported from mainline
	2019-05-10  Jakub Jelinek  <jakub@redhat.com>

	PR pch/90326
cp/
	* config-lang.in (gtfiles): Remove c-family/c-lex.c, add
	c-family/c-cppbuiltin.c.
objc/
	* config-lang.in (gtfiles): Add c-family/c-format.c.
objcp/
	* config-lang.in (gtfiles): Don't add c-family/c-cppbuiltin.c.
testsuite/
	* g++.dg/pch/pr90326.C: New test.
	* g++.dg/pch/pr90326.Hs: New file.

Added:
    branches/gcc-9-branch/gcc/testsuite/g++.dg/pch/pr90326.C
    branches/gcc-9-branch/gcc/testsuite/g++.dg/pch/pr90326.Hs
Modified:
    branches/gcc-9-branch/gcc/cp/ChangeLog
    branches/gcc-9-branch/gcc/cp/config-lang.in
    branches/gcc-9-branch/gcc/objc/ChangeLog
    branches/gcc-9-branch/gcc/objc/config-lang.in
    branches/gcc-9-branch/gcc/objcp/ChangeLog
    branches/gcc-9-branch/gcc/objcp/config-lang.in
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2019-08-29 14:59:50 UTC
Author: jakub
Date: Thu Aug 29 14:59:18 2019
New Revision: 275037

URL: https://gcc.gnu.org/viewcvs?rev=275037&root=gcc&view=rev
Log:
	Backported from mainline
	2019-05-10  Jakub Jelinek  <jakub@redhat.com>

	PR pch/90326
cp/
	* config-lang.in (gtfiles): Remove c-family/c-lex.c, add
	c-family/c-cppbuiltin.c.
objc/
	* config-lang.in (gtfiles): Add c-family/c-format.c.
objcp/
	* config-lang.in (gtfiles): Don't add c-family/c-cppbuiltin.c.
testsuite/
	* g++.dg/pch/pr90326.C: New test.
	* g++.dg/pch/pr90326.Hs: New file.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/pch/pr90326.C
    branches/gcc-8-branch/gcc/testsuite/g++.dg/pch/pr90326.Hs
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/config-lang.in
    branches/gcc-8-branch/gcc/objc/ChangeLog
    branches/gcc-8-branch/gcc/objc/config-lang.in
    branches/gcc-8-branch/gcc/objcp/ChangeLog
    branches/gcc-8-branch/gcc/objcp/config-lang.in
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2019-08-30 12:45:35 UTC
Author: jakub
Date: Fri Aug 30 12:45:01 2019
New Revision: 275157

URL: https://gcc.gnu.org/viewcvs?rev=275157&root=gcc&view=rev
Log:
	Backported from mainline
	2019-05-10  Jakub Jelinek  <jakub@redhat.com>

	PR pch/90326
cp/
	* config-lang.in (gtfiles): Remove c-family/c-lex.c, add
	c-family/c-cppbuiltin.c.
objcp/
	* config-lang.in (gtfiles): Remove c-family/c-lex.c, add
	c-family/c-cppbuiltin.c.
testsuite/
	* g++.dg/pch/pr90326.C: New test.
	* g++.dg/pch/pr90326.Hs: New file.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/pch/pr90326.C
    branches/gcc-7-branch/gcc/testsuite/g++.dg/pch/pr90326.Hs
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/config-lang.in
    branches/gcc-7-branch/gcc/objcp/ChangeLog
    branches/gcc-7-branch/gcc/objcp/config-lang.in
    branches/gcc-7-branch/gcc/testsuite/ChangeLog