[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 09:27:51 PDT 2024
================
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -verify %s
+
+#pragma clang diagnostic ignored "-Wperf-constraint-implies-noexcept"
+
+// Objective-C
+ at interface OCClass
+- (void)method;
+ at end
+
+void nl14(OCClass *oc) [[clang::nonblocking]] {
+ [oc method]; // expected-warning {{'nonblocking' function must not access an ObjC method or property}}
+}
----------------
dougsonos wrote:
Yeah... This gets into territory I hadn't ventured into yet, since `super` can't appear outside of the context of an ObjC method (right?), and currently, `nonblocking` and `nonallocating` are ignored on ObjC methods. The rationale was that you have to bend over backwards to bypass the ObjC runtime and call a method safely, and once you're in a method, you can't do much at all safely, so is it really worth the trouble?
So maybe the first question is how to fix this bug -- the following generates no diagnostics:
```
@implementation Derived
- (void)problem __attribute((nonblocking)) {
throw 42;
}
@end
```
The easiest solution is to forbid the attribute in this context.
https://github.com/llvm/llvm-project/pull/99656
More information about the cfe-commits
mailing list