]> granicus.if.org Git - clang/commitdiff
Don't warn about -Wshorten-64-to-32 in unreachable code. Fixes <rdar://problem/10759...
authorTed Kremenek <kremenek@apple.com>
Tue, 31 Jan 2012 05:37:48 +0000 (05:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 31 Jan 2012 05:37:48 +0000 (05:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149359 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/conversion-64-32.c

index cd9d071a24bde6d9c7e4ade523ddc64ab3f3b41c..b02e5b598aa1aaf8c24540960f81abf390c7f31e 100644 (file)
@@ -3693,15 +3693,24 @@ static void AnalyzeAssignment(Sema &S, BinaryOperator *E) {
 
 /// Diagnose an implicit cast;  purely a helper for CheckImplicitConversion.
 static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T, 
-                            SourceLocation CContext, unsigned diag) {
+                            SourceLocation CContext, unsigned diag,
+                            bool pruneControlFlow = false) {
+  if (pruneControlFlow) {
+    S.DiagRuntimeBehavior(E->getExprLoc(), E,
+                          S.PDiag(diag)
+                            << SourceType << T << E->getSourceRange()
+                            << SourceRange(CContext));
+    return;
+  }
   S.Diag(E->getExprLoc(), diag)
     << SourceType << T << E->getSourceRange() << SourceRange(CContext);
 }
 
 /// Diagnose an implicit cast;  purely a helper for CheckImplicitConversion.
 static void DiagnoseImpCast(Sema &S, Expr *E, QualType T,
-                            SourceLocation CContext, unsigned diag) {
-  DiagnoseImpCast(S, E, E->getType(), T, CContext, diag);
+                            SourceLocation CContext, unsigned diag,
+                            bool pruneControlFlow = false) {
+  DiagnoseImpCast(S, E, E->getType(), T, CContext, diag, pruneControlFlow);
 }
 
 /// Diagnose an implicit cast from a literal expression. Does not warn when the
@@ -3907,7 +3916,8 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
       return;
     
     if (SourceRange.Width == 64 && TargetRange.Width == 32)
-      return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_64_32);
+      return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_64_32,
+                             /* pruneControlFlow */ true);
     return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_precision);
   }
 
index 112e995102c59e6aac0ab9e1842136934ae31e66..62db7dcd2e7feba742cb1c871b1bb8f6175ae14f 100644 (file)
@@ -13,3 +13,23 @@ int4 test1(long2 a) {
   int4  v127 = a;  // no warning.
   return v127; 
 }
+
+// <rdar://problem/10759934>
+// Don't warn about -Wshorten-64-to-32 in unreachable code.
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+int rdar10759934() {
+  uint32_t thing = 0;
+  uint64_t thing2 = 0;
+
+  switch (sizeof(thing2)) {
+  case 8:
+    break;
+  case 4:
+    thing = thing2; // no-warning
+  default:
+    break;
+  }
+
+  return 0;
+}