================
@@ -743,6 +743,20 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
     CallerType.Func = CallerDecl->getType()->getAs<FunctionProtoType>();
   }
 
+  if (Context.getTargetInfo().getTriple().isPPC()) {
+    if (Context.getTargetInfo().getTriple().isOSAIX())
+      return Diag(St->getBeginLoc(), diag::err_aix_musttail_unsupported);
+    else if (!Context.getTargetInfo().hasFeature("pcrelative-memops")) {
+      if (Context.getTargetInfo().hasFeature("longcall"))
+        return Diag(St->getBeginLoc(), diag::err_ppc_impossible_musttail) << 0;
+      else if (!CE->getDirectCallee())
+        return Diag(St->getBeginLoc(), diag::err_ppc_impossible_musttail) << 1;
+      else if (isa_and_nonnull<FunctionDecl>(CE->getCalleeDecl()) &&
----------------
chenzheng1030 wrote:

Thanks for comment. @efriedma-quic 

Tried the below two cases:
- case 1:
```
int func2();
int external_call2() {
  [[clang::musttail]] return func2();
}

int func2() {
  return 0;
}
```

I think this should be a valid case for tailcall optimization, right? 
`isDefined()` returns true for the callee, but current `checkMustTailAttr()` 
treats this as an invalid musttail case. See https://godbolt.org/z/79sYfveds

- case 2:
```
__attribute__((weak)) int func2() {
  return 0;
}
int external_call2() {
  [[clang::musttail]] return func2();
}
```
With this patch, I get:
```
error: 'musttail' attribute for this call is impossible because external calls 
can not be tail called on PPC
```

I think the diagnose message is right? We have no way to know if there is any 
strong definition for this weak function, so maybe we should treat it as 
external calls?

To me, the two cases(if my case 2 can reflect your weak linkage case) are both 
handled correctly with `isDefined()`, although current `checkMustTailAttr()` 
does not work well for the functions that have both declaration and definition 
in the same file.

https://github.com/llvm/llvm-project/pull/93267
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to