From ea409449aabae46cbca70b25be4b87b356014418 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Fri, 15 Jan 2010 23:33:51 +0000 Subject: [PATCH] Generalize handling for unreachable code warnings to all binary operators. llvm-svn: 93584 --- clang/lib/Sema/SemaDecl.cpp | 29 +++++++++++++---------------- clang/test/Sema/warn-unreachable.c | 8 ++++---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d81e187bb304..b308613a46f7 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1339,24 +1339,21 @@ static SourceLocation GetUnreachableLoc(CFGBlock &b) { switch (S->getStmtClass()) { case Expr::BinaryOperatorClass: { - BinaryOperator *Op = cast(S); - if (Op->getOpcode() == BinaryOperator::Comma) { - if (b.size() < 2) { - CFGBlock *n = &b; - while (1) { - if (n->getTerminator()) - return n->getTerminator()->getLocStart(); - if (n->succ_size() != 1) - return SourceLocation(); - n = n[0].succ_begin()[0]; - if (n->pred_size() != 1) - return SourceLocation(); - if (!n->empty()) - return n[0][0].getStmt()->getLocStart(); - } + if (b.size() < 2) { + CFGBlock *n = &b; + while (1) { + if (n->getTerminator()) + return n->getTerminator()->getLocStart(); + if (n->succ_size() != 1) + return SourceLocation(); + n = n[0].succ_begin()[0]; + if (n->pred_size() != 1) + return SourceLocation(); + if (!n->empty()) + return n[0][0].getStmt()->getLocStart(); } - return b[1].getStmt()->getLocStart(); } + return b[1].getStmt()->getLocStart(); } default: ; } diff --git a/clang/test/Sema/warn-unreachable.c b/clang/test/Sema/warn-unreachable.c index 08ad6536987b..205c39c6e2cc 100644 --- a/clang/test/Sema/warn-unreachable.c +++ b/clang/test/Sema/warn-unreachable.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value int halt() __attribute__((noreturn)); int live(); @@ -35,9 +35,9 @@ void test2() { dead(); // expected-warning {{will never be executed}} case 3: - live(), - halt(); - dead(); // expected-warning {{will never be executed}} + live() + + halt(); + dead(); // expected-warning {{will never be executed}} case 4: a4: