mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 13:50:11 +00:00
[clang][diagnostics] Don't warn about unreachable code in constexpr if
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. Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D131818
This commit is contained in:
parent
3a8d7fe201
commit
ff8aadf58d
@ -299,6 +299,12 @@ static bool shouldTreatSuccessorsAsReachable(const CFGBlock *B,
|
||||
if (isa<BinaryOperator>(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<IfStmt>(Term);
|
||||
IS != nullptr && IS->isConstexpr())
|
||||
return true;
|
||||
}
|
||||
|
||||
const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);
|
||||
|
@ -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 @@ void f(int a) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user