You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AST] Improve overflow diagnostics for fixed-point constant evaluation.
Summary:
Diagnostics for overflow were not being produced for fixed-point
evaluation. This patch refactors a bit of the evaluator and adds
a proper diagnostic for these cases.
Reviewers: rjmccall, leonardchan, bjope
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73188
charc_const=256.0uk; // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'char'}}
251
251
short _Accumsa_const5=256; // expected-warning{{implicit conversion from 256 cannot fit within the range of values for 'short _Accum'}}
252
252
unsigned short _Accumusa_const2=-2; // expected-warning{{implicit conversion from -2 cannot fit within the range of values for 'unsigned short _Accum'}}
253
+
254
+
short _Accumadd_ovf1=255.0hk+20.0hk; // expected-warning {{overflow in expression; result is -237.0 with type 'short _Accum'}}
255
+
short _Accumadd_ovf2=10+0.5hr; // expected-warning {{overflow in expression; result is 0.5 with type 'short _Fract'}}
256
+
short _Accumsub_ovf1=16.0uhk-32.0uhk; // expected-warning {{overflow in expression; result is 240.0 with type 'unsigned short _Accum'}}
257
+
short _Accumsub_ovf2=-255.0hk-20; // expected-warning {{overflow in expression; result is 237.0 with type 'short _Accum'}}
258
+
short _Accummul_ovf1=200.0uhk*10.0uhk; // expected-warning {{overflow in expression; result is 208.0 with type 'unsigned short _Accum'}}
259
+
short _Accummul_ovf2= (-0.5hr-0.5hr) * (-0.5hr-0.5hr); // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
260
+
short _Accumdiv_ovf1=255.0hk / 0.5hk; // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}}
261
+
262
+
// No warnings for saturation
263
+
short _Fractadd_sat= (_Sat short_Fract)0.5hr+0.5hr;
264
+
short _Accumsub_sat= (_Sat short_Accum)-200.0hk-80.0hk;
265
+
short _Accummul_sat= (_Sat short_Accum)80.0hk*10.0hk;
266
+
short _Fractdiv_sat= (_Sat short_Fract)0.9hr / 0.1hr;
0 commit comments