r285657 - [ReachableCode] Skip over ExprWithCleanups in isConfigurationValue

Tim Shen via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 17:19:04 PDT 2016


Author: timshen
Date: Mon Oct 31 19:19:04 2016
New Revision: 285657

URL: http://llvm.org/viewvc/llvm-project?rev=285657&view=rev
Log:
[ReachableCode] Skip over ExprWithCleanups in isConfigurationValue

Summary: Fixes pr29152.

Reviewers: rsmith, pirama, krememek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24010

Added:
    cfe/trunk/test/SemaCXX/PR29152.cpp
Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/Analysis/ReachableCode.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=285657&r1=285656&r2=285657&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Oct 31 19:19:04 2016
@@ -387,6 +387,9 @@ public:
   /// Skip past any implicit AST nodes which might surround this
   /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
   Stmt *IgnoreImplicit();
+  const Stmt *IgnoreImplicit() const {
+    return const_cast<Stmt *>(this)->IgnoreImplicit();
+  }
 
   /// \brief Skip no-op (attributed, compound) container stmts and skip captured
   /// stmt at the top, if \a IgnoreCaptured is true.

Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=285657&r1=285656&r2=285657&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Mon Oct 31 19:19:04 2016
@@ -164,6 +164,8 @@ static bool isConfigurationValue(const S
   if (!S)
     return false;
 
+  S = S->IgnoreImplicit();
+
   if (const Expr *Ex = dyn_cast<Expr>(S))
     S = Ex->IgnoreCasts();
 

Added: cfe/trunk/test/SemaCXX/PR29152.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR29152.cpp?rev=285657&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR29152.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR29152.cpp Mon Oct 31 19:19:04 2016
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunreachable-code -verify %s
+
+static const bool False = false;
+
+struct A {
+  ~A();
+  operator bool();
+};
+void Bar();
+
+void Foo() {
+  if (False && A()) {
+    Bar(); // expected-no-diagnostics
+  }
+}




More information about the cfe-commits mailing list