[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
Doug Wyatt via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 08:33:11 PDT 2024
================
@@ -0,0 +1,194 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -verify %s
+// These are in a separate file because errors (e.g. incompatible attributes) currently prevent
+// the AnalysisBasedWarnings pass from running at all.
+
+// This diagnostic is re-enabled and exercised in isolation later in this file.
+#pragma clang diagnostic ignored "-Wperf-constraint-implies-noexcept"
+
+// --- CONSTRAINTS ---
+
+void nl1() [[clang::nonblocking]]
+{
+ auto* pInt = new int; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
+}
----------------
dougsonos wrote:
The surprising thing about function calls is that all of those functions are assumed to be unsafe because they aren't declared `nonblocking` or `nonallocating`. So an attempt to use any of those will result in the diagnostic:
'nonblocking' function must not call non-'nonblocking' function
A nice thing about this is that there's no need to maintain allow/deny lists.
https://github.com/llvm/llvm-project/pull/99656
More information about the cfe-commits
mailing list