[cfe-commits] r96545 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/switch.c
Douglas Gregor
dgregor at apple.com
Wed Feb 17 16:56:02 PST 2010
Author: dgregor
Date: Wed Feb 17 18:56:01 2010
New Revision: 96545
URL: http://llvm.org/viewvc/llvm-project?rev=96545&view=rev
Log:
Don't diagnose overflow in case statements when the conversion is a
signed<->unsigned conversion with the same bit width. Fixes
<rdar://problem/7658121>.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Sema/switch.c
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=96545&r1=96544&r2=96545&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 17 18:56:01 2010
@@ -340,11 +340,11 @@
} else if (NewSign != Val.isSigned()) {
// Convert the sign to match the sign of the condition. This can cause
// overflow as well: unsigned(INTMIN)
+ // We don't diagnose this overflow, because it is implementation-defined
+ // behavior.
+ // FIXME: Introduce a second, default-ignored warning for this case?
llvm::APSInt OldVal(Val);
Val.setIsSigned(NewSign);
-
- if (Val.isNegative()) // Sign bit changes meaning.
- Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
}
}
Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=96545&r1=96544&r2=96545&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Wed Feb 17 18:56:01 2010
@@ -240,3 +240,17 @@
}
return -1;
}
+
+// <rdar://problem/7658121>
+enum {
+ EC0 = 0xFFFF0000,
+ EC1 = 0xFFFF0001,
+};
+
+int test14(int a) {
+ switch(a) {
+ case EC0: return 0;
+ case EC1: return 1;
+ }
+ return 0;
+}
More information about the cfe-commits
mailing list