Bug 23550 – ImportC: Constant folding doesn't follow C99 semantics

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-12-11T14:59:56Z
Last change time
2024-12-13T19:26:20Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#20203 →

Comments

Comment #0 by ibuclaw — 2022-12-11T14:59:56Z
DMD doesn't follow section 5.2.4.2.2 Characteristics of floating types. Specifically: --- Except for assignment and cast (which remove all extra range and precision), the values yielded by operators with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than required by the type. The use of evaluation formats is characterized by the implementation-defined value of FLT_EVAL_METHOD. -1 indeterminable; 0 evaluate all operations and constants just to the range and precision of the type; 1 evaluate operations and constants of type float and double to the range and precision of the double type, evaluate long double operations and constants to the range and precision of the long double type; 2 evaluate all operations and constants to the range and precision of the long double type. All other negative values for FLT_EVAL_METHOD characterize implementation-defined behavior. --- Typically the default value of __FLT_EVAL_METHOD__ is 0. DMD evaluates operations at compile-time as-if __FLT_EVAL_METHOD__ is 2. e.g: --- #include <stdint.h> #include <stdlib.h> int main() { int64_t a = INT64_MIN; int64_t b = INT64_MAX; double c = 0.0; if (-1 != (a + b) + c) abort(); if (-1 != (INT64_MIN + INT64_MAX) + 0.0) abort(); if ( 0 != a + (b + c)) abort(); if ( 0 != INT64_MIN + (INT64_MAX + 0.0)) abort(); // fails if ( 0 != a + (double)(b)) abort(); if ( 0 != INT64_MIN + (double)(INT64_MAX)) abort(); // fails } ---
Comment #1 by dlang-bot — 2022-12-13T07:40:05Z
@WalterBright created dlang/dmd pull request #14694 "fix Issue 23550 - ImportC: Constant folding doesn't follow C99 semantics" fixing this issue: - fix Issue 23550 - ImportC: Constant folding doesn't follow C99 semantics https://github.com/dlang/dmd/pull/14694
Comment #2 by robert.schadek — 2024-12-13T19:26:20Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20203 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB