[PATCH] D96832: [Clang][Attributes] Allow not_tail_called attribute to be applied to virtual function.

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 15:45:35 PST 2021


ahatanak added a comment.

In D96832#2569481 <https://reviews.llvm.org/D96832#2569481>, @zequanwu wrote:

> In D96832#2568257 <https://reviews.llvm.org/D96832#2568257>, @aaron.ballman wrote:
>
>> It was explicitly disallowed in the initial patch: https://reviews.llvm.org/D12922 and the original author said "I'm still trying to figure out the best way to handle c++ virtual functions: this attribute is not very useful for someone who is looking for a way to reliably prevent tail-call to a virtual function." and "I made this change because this attribute isn't useful when the compiler cannot resolve the function call statically at compile time and it isn't important for the use case I have." Has this situation changed in the backend?
>
> Oh, I didn't see that. But when I tested `not_tail_called` on normal functions,  it seems like not working(https://godbolt.org/z/znr5b5, `f1` is marked as `not_tail_called`, it still get inlined). Or, I misunderstand how to use it properly?

I'm still trying to remember the discussions we had, but I think we banned the attribute on virtual functions because you can't in general promise a call to an annotated function won't be tail called if the function is virtual.

This patch doesn't prevent the call to `method` in the code below from being tail called, but I suppose users would except the attribute to prevent the tail call?

  struct B {
    virtual void method();  
  };
  
  struct D : B {
    [[clang::not_tail_called]] void method() override; 
  };
  
  void test(D *d) {
    B *b = D;
    b->method();
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96832



More information about the cfe-commits mailing list