Summary: | wrong code at -O2 and -O3 on x86_64-linux-gnu | ||
---|---|---|---|
Product: | gcc | Reporter: | Zhendong Su <su> |
Component: | tree-optimization | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | jakub |
Priority: | P3 | ||
Version: | 4.7.4 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Zhendong Su
2014-02-16 20:28:05 UTC
Note there is no overflow happening here at all. In that a++ is the same as a = a + 1 which is the same as a = (short)(((int)a) + 1) due to promotion rules in C. Technically there is an overflow there. But GCC defines conversion to a smaller signed integer type, when the value cannot be represented in that smaller type, as a non-signalling truncation. Still, portable code mustn't rely on that. Well, the conversion is implementation-defined behavior, and GCC documents what it does in that case (does it?) and thus you can rely on it, and given that other compilers also have simimilar implementation-defined behavior choice for that case, you can portably assume it unless you are targetting extinct architectures. |