[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

Doug Wyatt via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 20:15:31 PDT 2024


================
@@ -2397,6 +2397,1262 @@ class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler {
 };
 } // namespace
 
+// =============================================================================
+
+namespace FXAnalysis {
+
+enum class DiagnosticID : uint8_t {
+  None = 0, // sentinel for an empty Diagnostic
+  Throws,
+  Catches,
+  CallsObjC,
+  AllocatesMemory,
+  HasStaticLocal,
+  AccessesThreadLocal,
+
+  // These only apply to callees, where the analysis stops at the Decl
+  DeclDisallowsInference,
+
+  CallsDeclWithoutEffect,
+  CallsExprWithoutEffect,
+};
+
+// Holds an effect diagnosis, potentially for the entire duration of the
+// analysis phase, in order to refer to it when explaining why a caller has been
+// made unsafe by a callee.
+struct Diagnostic {
----------------
dougsonos wrote:

This class is serving as an abstraction to unify the warning when a `nonblocking` (etc) function blocks, vs. the note when a function's caller is attempting to infer it as `nonblocking` and fails because the function blocks.

There are many (6?) of these diagnostics that come in pairs, a warning and a note. This `Diagnostic` class represents the exact unsafe construct and has no opinion about whether it needs to be reported as a warning or a note; there's one function that converts it into a regular diagnostic given the context.

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


More information about the cfe-commits mailing list