]> granicus.if.org Git - clang/commitdiff
Improve unreachable code warnings for with respect to ? :.
authorMike Stump <mrs@apple.com>
Thu, 21 Jan 2010 19:44:04 +0000 (19:44 +0000)
committerMike Stump <mrs@apple.com>
Thu, 21 Jan 2010 19:44:04 +0000 (19:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/warn-unreachable.c
test/SemaCXX/warn-unreachable.cpp

index 8fdb5ec87eb3109fe250bc822304827b5422f2da..9fadd45fbbbd1c5d0632f0f567b31317ee1a26bc 100644 (file)
@@ -2067,8 +2067,12 @@ static unsigned MarkLive(CFGBlock *e, llvm::BitVector &live) {
 static SourceLocation GetUnreachableLoc(CFGBlock &b, SourceRange &R1,
                                         SourceRange &R2) {
   Stmt *S;
-  if (!b.empty())
-    S = b[0].getStmt();
+  unsigned sn = 0;
+  R1 = R2 = SourceRange();
+
+  top:
+  if (sn < b.size())
+    S = b[sn].getStmt();
   else if (b.getTerminator())
     S = b.getTerminator();
   else
@@ -2078,8 +2082,8 @@ static SourceLocation GetUnreachableLoc(CFGBlock &b, SourceRange &R1,
   case Expr::BinaryOperatorClass: {
     BinaryOperator *BO = cast<BinaryOperator>(S);
     if (BO->getOpcode() == BinaryOperator::Comma) {
-      if (b.size() >= 2)
-        return b[1].getStmt()->getLocStart();
+      if (sn+1 < b.size())
+        return b[sn+1].getStmt()->getLocStart();
       CFGBlock *n = &b;
       while (1) {
         if (n->getTerminator())
@@ -2108,6 +2112,13 @@ static SourceLocation GetUnreachableLoc(CFGBlock &b, SourceRange &R1,
     R2 = CAO->getRHS()->getSourceRange();
     return CAO->getOperatorLoc();
   }
+  case Expr::ConditionalOperatorClass: {
+    const ConditionalOperator *CO = cast<ConditionalOperator>(S);
+    return CO->getQuestionLoc();
+  }
+  case Expr::ImplicitCastExprClass:
+    ++sn;
+    goto top;
   case Stmt::CXXTryStmtClass: {
     return cast<CXXTryStmt>(S)->getHandler(0)->getCatchLoc();
   }
index fc56a87286b7abefb953a5902cbfa91a2ccf08c8..7c913cafb245753fbd88d52f574cdee5176068dc 100644 (file)
@@ -83,5 +83,9 @@ void test2() {
     i
       +=        // expected-warning {{will never be executed}}
       halt();
+  case 9:
+    halt()
+      ?         // expected-warning {{will never be executed}}
+      dead() : dead();
   }
 }
index a1f0dabec364b08245d812cda3b342fcfd6c76af..852943f01da842f115c40a4d0cd512b829126f4c 100644 (file)
@@ -39,4 +39,7 @@ void test2() {
 void test3() {
   halt()
     --;         // expected-warning {{will never be executed}}
+  halt()
+    ?         // expected-warning {{will never be executed}}
+    dead() : dead();
 }