[PATCH] D152986: [clang] Allow 'nomerge' attribute for function pointers
Reid Kleckner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 15 11:44:47 PDT 2023
rnk added a comment.
The purpose of the attribute is really limited to preserving source location information on instructions, and this isn't really a supported usage. The BPF backend and verifier needs to learn to tolerate valid LLVM transforms if it wants to be a real LLVM backend. Of course, you can do what you like.
Considered in the context of the original use case, I think it's reasonable to allow the attribute on function pointers for the same reasons we allow it on function declarations. It makes it easy to work the attribute onto the direct call sites of the function without modifying tons of source code. However, I'd like to see clearer documentation on the limitations.
================
Comment at: clang/include/clang/Basic/AttrDocs.td:551-555
calls to the specified function from merging. It has no effect on indirect
calls.
+
+``nomerge`` attribute can be specified for pointers to functions, all
+calls done through such pointer would be protected from merging.
----------------
This statement of the attribute having "no effect on indirect calls" is slightly confusing now that we talk about function pointers immediately afterward. Can you please rework this a bit, and clarify that when applied to function pointers, the attribute only takes effect when the call target is directly the variable which carries the attribute? For example, this has no effect:
```
void (*fp)() __attribute__((nomerge));
void callit() {
auto tmp = fp;
tmp();
(*fp)(); // I think TargetDecl will be null in the code, tell me if I'm wrong
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152986/new/
https://reviews.llvm.org/D152986
More information about the cfe-commits
mailing list