[all-commits] [llvm/llvm-project] df95df: [clang]: Support `analyzer_noreturn` attribute in ...

Andrey Karlov via All-commits all-commits at lists.llvm.org
Mon Sep 1 08:02:31 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: df95dfcf5a1e900801fdaa50daa63df16ca86fc3
      https://github.com/llvm/llvm-project/commit/df95dfcf5a1e900801fdaa50daa63df16ca86fc3
  Author: Andrey Karlov <dein.negativ at gmail.com>
  Date:   2025-09-01 (Mon, 01 Sep 2025)

  Changed paths:
    M clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
    M clang/include/clang/AST/Decl.h
    M clang/lib/AST/Decl.cpp
    M clang/lib/Analysis/CFG.cpp
    M clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

  Log Message:
  -----------
  [clang]: Support `analyzer_noreturn` attribute in `CFG` (#150952)

## Problem

Currently, functions with `analyzer_noreturn` attribute aren't
recognized as `no-return` by `CFG`:

```cpp
void assertion_handler() __attribute__((analyzer_noreturn)) {
    log(...);
}

void handle_error(const std::optional<int> opt) {
    if (!opt) {
        fatal_error(); // Static analyzer doesn't know this never returns
    }
    *opt = 1;          // False-positive `unchecked-optional-access` warning as analyzer thinks this is reachable
}
```

## Solution
1. Extend the `FunctionDecl` class by adding an `isAnalyzerNoReturn()`
function
2. Update `CFGBuilder::VisitCallExpr` to check both `FD->isNoReturn()`
and `FD->isAnalyzerNoReturn()` properties

## Comments
This PR incorporates part of the work done in
https://github.com/llvm/llvm-project/pull/146355



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list