https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126003
Bug ID: 126003
Summary: integer overflow during compile-time arithmetic is not
always detected
Product: gcc
Version: 13.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: douglas.mcilroy at dartmouth dot edu
Target Milestone: ---
The program below contains two instances of integer overflow. Under option -O1,
both are evaluated at compile time, yet only the first one gives a warning.
This seems inconsistent. At best, an opportunity to get better warnngs as a
side-effect of optimization has been wasted.
#include <stdio.h>
#define TWOGIG 2000000000 // 2,000,000,000
int x = TWOGIG+TWOGIG;
int main() {
int twogig = TWOGIG;
printf("%d\n", twogig+twogig);
}