[cfe-commits] r94115 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/warn-unreachable.c test/SemaCXX/warn-unreachable.cpp

Mike Stump mrs at apple.com
Thu Jan 21 15:15:54 PST 2010


Author: mrs
Date: Thu Jan 21 17:15:53 2010
New Revision: 94115

URL: http://llvm.org/viewvc/llvm-project?rev=94115&view=rev
Log:
Improve unreachable code warnings with respect to dead member and
dead array references.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/warn-unreachable.c
    cfe/trunk/test/SemaCXX/warn-unreachable.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=94115&r1=94114&r2=94115&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Jan 21 17:15:53 2010
@@ -2116,6 +2116,17 @@
     const ConditionalOperator *CO = cast<ConditionalOperator>(S);
     return CO->getQuestionLoc();
   }
+  case Expr::MemberExprClass: {
+    const MemberExpr *ME = cast<MemberExpr>(S);
+    R1 = ME->getSourceRange();
+    return ME->getMemberLoc();
+  }
+  case Expr::ArraySubscriptExprClass: {
+    const ArraySubscriptExpr *ASE = cast<ArraySubscriptExpr>(S);
+    R1 = ASE->getLHS()->getSourceRange();
+    R2 = ASE->getRHS()->getSourceRange();
+    return ASE->getRBracketLoc();
+  }
   case Expr::CStyleCastExprClass: {
     const CStyleCastExpr *CSC = cast<CStyleCastExpr>(S);
     R1 = CSC->getSubExpr()->getSourceRange();
@@ -2134,6 +2145,7 @@
   }
   default: ;
   }
+  R1 = S->getSourceRange();
   return S->getLocStart();
 }
 

Modified: cfe/trunk/test/Sema/warn-unreachable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unreachable.c?rev=94115&r1=94114&r2=94115&view=diff

==============================================================================
--- cfe/trunk/test/Sema/warn-unreachable.c (original)
+++ cfe/trunk/test/Sema/warn-unreachable.c Thu Jan 21 17:15:53 2010
@@ -90,5 +90,11 @@
   case 10:
     (           // expected-warning {{will never be executed}}
       float)halt();
+  case 11: {
+    int a[5];
+    live(),
+      a[halt()
+        ];      // expected-warning {{will never be executed}}
+  }
   }
 }

Modified: cfe/trunk/test/SemaCXX/warn-unreachable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unreachable.cpp?rev=94115&r1=94114&r2=94115&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unreachable.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unreachable.cpp Thu Jan 21 17:15:53 2010
@@ -46,3 +46,31 @@
     float       // expected-warning {{will never be executed}}
       (halt());
 }
+
+void test4() {
+  struct S {
+    int mem;
+  } s;
+  S &foor();
+  halt(), foor()
+    .mem;       // expected-warning {{will never be executed}}
+}
+
+void test5() {
+  struct S {
+    int mem;
+  } s;
+  S &foor() __attribute__((noreturn));
+  foor()
+    .mem;       // expected-warning {{will never be executed}}
+}
+
+void test6() {
+  struct S {
+    ~S() { }
+    S(int i) { }
+  };
+  live(),
+    S            // expected-warning {{will never be executed}}
+      (halt());
+}





More information about the cfe-commits mailing list