On Feb 23, 2011, at 3:34 PM, Chandler Carruth wrote: > Author: chandlerc > Date: Wed Feb 23 17:34:11 2011 > New Revision: 126342 > > URL: http://llvm.org/viewvc/llvm-project?rev=126342&view=rev > Log: > Implement a warning for known shift overflows on constant shift > expressions. Consider the code: > > int64_t i = 10 << 30; > > This compiles fine, but most developers expect it to produce the value > for 10 gigs, not -2 gigs. This is actually undefined behavior because > the LHS is a signed integer type. > > The warning is currently gated behind -Wshift-overflow.
Cool, thanks Chandler! The wording on these is a bit awkward though: +def warn_shift_result_gt_typewidth : Warning< + "shift result (%0) requires %1 bits to represent, but the promoted type of " + "the shift expression is %2 with only %3 bits">, + InGroup<DiagGroup<"shift-overflow">>; +def warn_shift_result_overrides_sign_bit : Warning< + "shift result (%0) overrides the sign bit of the promoted type of the shift " + "expression (%1) and becomes negative">, + InGroup<DiagGroup<"shift-sign-overflow">>, DefaultIgnore; Mentioning the "promoted type" doesn't make sense in a lot of cases (when there is no promotion happening). It seems completely fine to simplify it to: "shift result (%0) requires %1 bits to represent, but %2 only has %3 bits" What do you think? -Chris _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
