[PATCH] D79121: Add nomerge function attribute to clang

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 30 12:21:12 PDT 2020


aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

This should also have Sema tests ensuring that it only applies to the correct subjects, accepts no arguments, etc.



================
Comment at: clang/include/clang/Basic/Attr.td:1799
+  let Spellings = [Clang<"nomerge">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoMergeDocs];
----------------
zequanwu wrote:
> rnk wrote:
> > Clang supports many function-like things that are not functions, for example, Objective C method declarations are not considered FunctionDecls in the AST. Blocks are another function-like thing. I see below there is a `FunctionLike` subject type. Lets use that here.
> > 
> > I would like to make it possible to apply this attribute directly to call expressions as well, but I don't see a good example of how to do that in the existing attribute. I'd like to be able to do this, for example:
> > 
> > ```
> > void __attribute__((noreturn)) bar();
> > void foo(bool cond) {
> >   if (cond)
> >     [[clang::nomerge]] bar();
> >   else
> >     [[clang::nomerge]] bar();
> > }
> > ```
> > 
> > This gives the user fine-grained control. It allows them to call some existing API, like perhaps RaiseException, of which they do not control the declaration, and mark the calls as unmergeable.
> It seems like there is no exiting example of call site attributes. https://github.com/llvm/llvm-project/blob/master/clang/lib/CodeGen/CGCall.cpp#L4767. And the function `EmitCall` may not know existence of call site attributes.
> I would like to make it possible to apply this attribute directly to call expressions as well, but I don't see a good example of how to do that in the existing attribute.

You would have to use a statement attribute rather than a declaration attribute for this, and we have a few of those but none that work on call expressions specifically.

One question I have about that idea is whether attributes give you fine enough levels of control (I don't know enough about `nomerge` to answer this myself). e.g., `foo(bar(), bar()); // Do you want to nomerge the bar() calls, the foo() call, or all three?` (You can only add the attribute to the statement expression, not to individual expressions.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79121/new/

https://reviews.llvm.org/D79121





More information about the cfe-commits mailing list