[clang] [clang-tools-extra] [clang]: Propagate `*noreturn` attributes in `CFG` (PR #146355)

Andrey Karlov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 06:10:00 PDT 2025


================
@@ -3596,6 +3596,16 @@ bool FunctionDecl::isNoReturn() const {
   return false;
 }
 
+std::optional<bool> FunctionDecl::getAnalyzerNoReturn() const {
+  if (isNoReturn())
+    return true;
+
+  if (auto *Attr = getAttr<AnalyzerNoReturnAttr>())
+    return Attr->getValue();
+
+  return std::nullopt;
----------------
negativ wrote:

We cannot use ` || hasAttr<AnalyzerNoReturnAttr>()` to return `true` here because these declarations are different:
```cpp
// getAnalyzerNoReturn() => std::nullopt as we don't have explicit value of `analyzer_noreturn` attr
void foo();
```
```cpp
// getAnalyzerNoReturn() => `false`, this function 100% returns control back to caller
void foo() __attribute__((analyzer_noreturn(false)));
```
```cpp
// getAnalyzerNoReturn() => `true`, this function  is no-return
void foo() __attribute__((analyzer_noreturn(true)));
```

https://github.com/llvm/llvm-project/pull/146355


More information about the cfe-commits mailing list