[clang] [llvm] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

Sander de Smalen via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 19 07:25:42 PST 2024


================
@@ -814,6 +821,42 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
                           /*allowHigherAlign*/ false);
 }
 
+void AArch64TargetCodeGenInfo::checkFunctionCallABI(
+    CodeGenModule &CGM, SourceLocation CallLoc, const FunctionDecl *Caller,
+    const FunctionDecl *Callee, const CallArgList &Args) const {
+  if (!Callee->hasAttr<AlwaysInlineAttr>())
+    return;
+
+  auto GetSMEAttrs = [](const FunctionDecl *F) {
+    llvm::SMEAttrs FAttrs;
+    if (F->hasAttr<ArmLocallyStreamingAttr>())
+      FAttrs.set(llvm::SMEAttrs::Mask::SM_Enabled);
+    if (auto *NewAttr = F->getAttr<ArmNewAttr>()) {
+      if (NewAttr->isNewZA())
+        FAttrs.set(llvm::SMEAttrs::Mask::ZA_New);
+    }
+    if (const auto *T = F->getType()->getAs<FunctionProtoType>()) {
+      if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
+        FAttrs.set(llvm::SMEAttrs::Mask::SM_Enabled);
+      if (T->getAArch64SMEAttributes() &
+          FunctionType::SME_PStateSMCompatibleMask)
+        FAttrs.set(llvm::SMEAttrs::Mask::SM_Compatible);
+    }
+    return FAttrs;
+  };
+
+  auto CalleeAttrs = GetSMEAttrs(Callee);
+  auto CallerAttrs = GetSMEAttrs(Caller);
+
+  if (CallerAttrs.requiresSMChange(CalleeAttrs, true))
+    CGM.getDiags().Report(CallLoc,
+                          diag::err_function_always_inline_attribute_mismatch)
+        << Caller->getDeclName() << Callee->getDeclName() << "streaming";
+  if (CalleeAttrs.hasNewZABody())
+    CGM.getDiags().Report(CallLoc, diag::err_function_always_inline_new_za)
+        << Callee->getDeclName();
+}
----------------
sdesmalen-arm wrote:

I think this is missing a check to see if the call requires the lazy-save mechanism as well.

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


More information about the cfe-commits mailing list