https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109294
Bug ID: 109294 Summary: Inconsistent exp function implementations for compile time and run time evaluation Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jdavidpeter at gmail dot com Target Milestone: --- Created attachment 54764 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54764&action=edit Raw and preprocessed source file reproducing the problem on WSL Ubuntu 20.04.5 LTS Implementation for exp function provides different results for certain inputs based on whether the call is evaluated compile time (e.g. constexpr) or runtime. Refer to the GodBolt link in PS as well as the attached, raw and preprocessed source. # System info: $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.5 LTS Release: 20.04 Codename: focal $ g++ --version g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # Repro steps: g++ bug.cpp -O0 -save-temps -o O0 g++ bug.cpp -O3 -save-temps -o O3 $ ./O0 d9bd1a4d d9bd1a4d d9bd1a4e $ ./O3 d9bd1a4d d9bd1a4e d9bd1a4e In the example, there are 3 calls to exp with the same input. 1. The first will always use the runtime implementation due to the volatile keyword on the variable. 2. The second uses runtime implementation in -O0 and compile time in -O3. 3. The third always uses compile time implementation based on the GodBolt assembly. Based on the calls, the same binary will provide different results for use case 1 vs 3 which is a bug. Also, the result will be different for use case 2 in -O0 and -O3, which is also a bug. I also question if the third call should be always optimized to a registry operation instead of calling the actual runtime exp. However, I didn't find any documentation on optimizations done in -O0, so this might be intentional. Would be less of a problem if the compile time and runtime implementation would yield the same input. This bug also manifests in gcc12. This isn't an issue for clang 16.0. PS: https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAM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