-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Description
I have a program which needs constant static data tables to be constant-initialized so they are available for global constructors and external parsing of the binary. This turns out to break if all of the following are true:
- The initialization also involves an expression which is not constexpr
- The flag
-ftrapping-mathis passed - A double precision float literal is assigned to a single precision float member
In this case, Clang decides to initialize the data tables with zero in the binary and fill them in at runtime, which is a problem.
I don't know if this is a bug, but it's unexpected and not something GCC does. I've prepared a godbolt example which demonstrates the problem and explains how to mitigate the problem by removing one of the above factors: https://godbolt.org/z/fs8v7h1hx . But I don't think we should have to apply any mitigation and there may be an issue in the compiler.
In the broken case, the table is zero and there's a bunch of extra code:
Container::data:
.zero 64
In the working case, the table is filled out:
Container::data:
.quad .str
.quad 0
.long 0x3ed70a3d
.zero 4
.zero 40