This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Issue a warning for integer overflow in struct initializer
ClosedPublic

Authored by ahatanak on Nov 30 2015, 4:30 PM.

Details

Summary

Issue a warning if an initializing integer expression overflows.

For example, clang should issue a warning when compiling the following code because 4 * 1024 * 1024 * 1024 doesn't fit into a 32-bit integer:

struct s {
unsigned x;
} s = {
.x = 4 * 1024 * 1024 * 1024
};

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 41451.Nov 30 2015, 4:30 PM
ahatanak retitled this revision from to [Sema] Issue a warning for integer overflow in struct initializer.
ahatanak updated this object.
ahatanak added a subscriber: cfe-commits.
vsk added a subscriber: vsk.Jan 8 2016, 1:36 PM

Looks good to me.

Caveat: This isn't quite my area. This seems reasonable given what I've read in EvaluateForOverflow and EvaluateAsRValue. I think you should be fine to commit if no one objects soon.

OK, thank you for the review.

I'll commit this patch in a day or two unless someone comes up with a better solution.

This revision was automatically updated to reflect the committed changes.