[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Alan Zhao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff8aadf58d1a: [clang][diagnostics] Dont warn about 
unreachable code in constexpr if (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

Files:
  clang/lib/Analysis/ReachableCode.cpp
  clang/test/SemaCXX/unreachable-code.cpp


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,34 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true) {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+
+  bool baz() {
+if constexpr (true)
+  return true;
+else {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in 
warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,34 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true) {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+
+  bool baz() {
+if constexpr (true)
+  return true;
+else {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D131818#3723227 , @thakis wrote:

> Thanks!
>
> Can you add a test for non-constexpr unreachable code within the constexpr if 
> and test that that still warns?

Done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 452721.
ayzhao added a comment.

Add tests for nested non-constexpr if


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

Files:
  clang/lib/Analysis/ReachableCode.cpp
  clang/test/SemaCXX/unreachable-code.cpp


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,34 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true) {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+
+  bool baz() {
+if constexpr (true)
+  return true;
+else {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in 
warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,34 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true) {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+
+  bool baz() {
+if constexpr (true)
+  return true;
+else {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks!

Can you add a test for non-constexpr unreachable code within the constexpr if 
and test that that still warns?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-12 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 452334.
ayzhao added a comment.

Add a test for non-constexpr if statements


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131818/new/

https://reviews.llvm.org/D131818

Files:
  clang/lib/Analysis/ReachableCode.cpp
  clang/test/SemaCXX/unreachable-code.cpp


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,19 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true)
+  return true;
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in 
warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,19 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true)
+  return true;
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131818: [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-12 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao created this revision.
ayzhao added a reviewer: thakis.
Herald added a reviewer: NoQ.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The point of a constexpr if statement is to determine which branch to
take at compile time, so warning on unreachable code is meaningless in
these situations.

Fixes #57123.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131818

Files:
  clang/lib/Analysis/ReachableCode.cpp
  clang/test/SemaCXX/unreachable-code.cpp


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,12 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true)
+  return true;
+else
+  return false; // no-warning
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in 
warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);


Index: clang/test/SemaCXX/unreachable-code.cpp
===
--- clang/test/SemaCXX/unreachable-code.cpp
+++ clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,12 @@
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true)
+  return true;
+else
+  return false; // no-warning
+  }
+}
Index: clang/lib/Analysis/ReachableCode.cpp
===
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits