[PATCH] Add a truncation warning for values under a bitwise or

Sam Panzer espanz at gmail.com
Thu Feb 14 12:53:43 PST 2013



================
Comment at: lib/Sema/SemaChecking.cpp:4782
@@ +4781,3 @@
+static bool IsBitwiseOrWithConstant(Sema &S, llvm::APSInt &Value, Expr *E) {
+  E = E->IgnoreImpCasts();
+  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
----------------
Dmitri Gribenko wrote:
> IgnoreParenImpCasts?  Does `x = (y | 0xfff);`work?  Please add this test anyway.
This wasn't needed to pass the test, since Sema::AnalyzeImplicitConversions() strips the parens already. I'm not sure if ignoring implicit casts here has any effect - is it possible to have an implicit cast from a compile-time constant to a narrower type? I don't *think* so.

================
Comment at: test/Sema/constant-conversion.c:94
@@ +93,3 @@
+	x = 0xff | y; // no-warning
+	x = (y | 0x1ff); // expected-warning {{implicit conversion from 'int' to 'unsigned char' changes value from 511 to 255}}
+	x = (y | 0xff); // no-warning
----------------
Dmitri's test suggestion added here.


http://llvm-reviews.chandlerc.com/D405



More information about the cfe-commits mailing list