ahatanak added a comment.

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

> In D96832#2569987 <https://reviews.llvm.org/D96832#2569987>, @ahatanak wrote:
>
>> 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();
>>   }
>
> I got the point about why preventing it on virtual functions. But, on the 
> above godbolt link, I provided a example where `not_tail_called` doesn't 
> prevent a non-virtual function from tail call. I wonder if I use it correctly.

`not_tail_called` adds `notail` to the call `c->f1` in the IR, but doesn't do 
anything to prevent the calls inside `f1` from being tail called. You can use 
`disable-tail-calls` instead for that purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96832

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to