[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 24 11:10:55 PDT 2024


================
@@ -5751,8 +5751,29 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
     if (TargetDecl && TargetDecl->hasAttr<NotTailCalledAttr>())
       Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
-    else if (IsMustTail)
+    else if (IsMustTail) {
+      if (getTarget().getTriple().isPPC()) {
+        if (getTarget().getTriple().isOSAIX())
+          CGM.getDiags().Report(Loc, diag::err_aix_musttail_unsupported);
+        else if (!getTarget().hasFeature("pcrelative-memops")) {
+          if (getTarget().hasFeature("longcall"))
+            CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 0;
+          else if (Call->isIndirectCall())
+            CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 1;
+          else if (isa_and_nonnull<FunctionDecl>(TargetDecl) &&
+                   cast<FunctionDecl>(TargetDecl)->isWeak())
----------------
efriedma-quic wrote:

This isn't the right way to check the definition is "weak", I think.  In addition to explicit weak attributes, you need some check for inline functions (both C and C++, which have different semantics).  Not sure what the CodeGen API for this is off the top of my head.

I think you also need to check for weak definitions in MustTailCallUndefinedGlobals.

https://github.com/llvm/llvm-project/pull/93267


More information about the cfe-commits mailing list