[clang] [ObjC] Enable diagnose_if on Objective-C methods (PR #115056)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 09:21:10 PST 2024


apple-fcloutier wrote:

I think there's limited value to diagnose_if on blocks, since that will apply to a variable of block type and not to the block type. In other words, given this:

```c
void (^block)(int *) = ^(int *p) __attribute__((diagnose_if(p == 0, "p is NULL"))) { ... };
block(0);
```

even assuming the we did all of the rest of the work (including piping the block through diagnose_if checks, which is non-trivial because BlockDecl isn't a NamedDecl), there would be no diagnostic when from a block type with diagnose_if to a block without it, and then no diagnostic when calling block(0).

There is almost certainly value in introducing a base class beneath ObjCMethodDecl and FunctionDecl that is both a NamedDecl and a DeclContext, because I'm not the first person to run into this problem. If I do the work, whose review/approval do we need? Is it deep enough in the guts of clang that it will take an RFC or is it something that we can reasonably thumbs-up in a PR?

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


More information about the cfe-commits mailing list