[clang] [clang] Forward Correct SourceLocation for Unreachable Code Diagnostics (PR #152839)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 9 00:15:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Vincent (Mr-Anyone)
<details>
<summary>Changes</summary>
fixes #<!-- -->152477
---
Full diff: https://github.com/llvm/llvm-project/pull/152839.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Analysis/ReachableCode.cpp (+5)
- (modified) clang/test/SemaCXX/warn-unreachable.cpp (+13)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 17e3df467593d..f3b21479c7470 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -178,6 +178,8 @@ Bug Fixes to C++ Support
- Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665)
- Suppress ``-Wdeprecated-declarations`` in implicitly generated functions. (#GH147293)
- Fix a crash when deleting a pointer to an incomplete array (#GH150359).
+- Diagnosing the correct location for a function with non-POD data return-type being
+ labeled ``[[noreturn]]``.
- Fix an assertion failure when expression in assumption attribute
(``[[assume(expr)]]``) creates temporary objects.
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 4a9ab5d9f0f73..c7de8836932a3 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -601,6 +601,11 @@ static SourceLocation GetUnreachableLoc(const Stmt *S,
S = Ex->IgnoreParenImpCasts();
switch (S->getStmtClass()) {
+ case Expr::CXXBindTemporaryExprClass: {
+ const CXXBindTemporaryExpr *TemporaryExpr = cast<CXXBindTemporaryExpr>(S);
+ R1 = TemporaryExpr->getTemporary()->getDestructor()->getSourceRange();
+ return R1.getBegin();
+ }
case Expr::BinaryOperatorClass: {
const BinaryOperator *BO = cast<BinaryOperator>(S);
return BO->getOperatorLoc();
diff --git a/clang/test/SemaCXX/warn-unreachable.cpp b/clang/test/SemaCXX/warn-unreachable.cpp
index e6f5bc5ef8e12..ce574cfafa8e1 100644
--- a/clang/test/SemaCXX/warn-unreachable.cpp
+++ b/clang/test/SemaCXX/warn-unreachable.cpp
@@ -414,3 +414,16 @@ void tautological_compare(bool x, int y) {
calledFun();
}
+
+namespace GH152477{
+ class A{
+ public:
+ ~A(); // expected-warning {{will never be executed}}
+ };
+
+ [[noreturn]] A never_return_so_destructor_never_called();
+
+ void func(){
+ never_return_so_destructor_never_called();
+ }
+};
``````````
</details>
https://github.com/llvm/llvm-project/pull/152839
More information about the cfe-commits
mailing list