[clang] [CIR] -Wreturn-type (1/2): Add an analysis classifying how control reaches a function's end (PR #239774)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 12 21:06:27 PST 2026


================
@@ -0,0 +1,713 @@
+//===- CIRFallOffAnalysis.cpp - Can control flow off the end of a function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A reachability walk over structured CIR. Each region reports how control
+// leaves it (falling through, break, continue, explicit return, or reaching an
+// `implicit` terminator), and each structured operation combines the exits of
+// its regions according to its semantics. Reachable noreturn calls, user
+// traps and throws are recorded as the abnormal and fake edges Sema's CFG
+// check uses to tell "maybe" from "always".
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CIR/Dialect/Analysis/CIRFallOffAnalysis.h"
----------------
bcardosolopes wrote:

I went with your strawman: it's now FunctionExitAnalysis (ba76942), which also matches what it computes internally, which kinds of exit a function can reach. The results moved from the CFG's never/maybe/always to MLIR-style may/must names: ReturnOnly, NoReturn, MayReachEnd and MustReachEnd. The pass is `-cir-function-exit-analysis`. Happy to change any of these if someone has a better idea.

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


More information about the cfe-commits mailing list