[clang] [llvm][Stmt]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 4 17:17:29 PDT 2025


https://github.com/MillePlateaux created https://github.com/llvm/llvm-project/pull/134465

Added judgment statements and accurately reported errors.Closes #133509

>From c7bd0c4413cbf4768105be178341ff169e460617 Mon Sep 17 00:00:00 2001
From: MillePlateaux <liulambda at outlook.com>
Date: Fri, 4 Apr 2025 16:26:25 -0700
Subject: [PATCH] [llvm][Stmt]:git clang format

---
 clang/lib/Sema/SemaStmt.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index e1b9ccc693bd5..c8354198a5614 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -717,6 +717,14 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
     return false;
   }
 
+  if (const FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
+    if (CalleeDecl->hasAttr<NotTailCalledAttr>()) {
+      Diag(St->getBeginLoc(), diag::err_musttail_conflicts_with_not_tail_called)
+          << &MTA;
+      return false;
+    }
+  }
+
   if (const auto *EWC = dyn_cast<ExprWithCleanups>(E)) {
     if (EWC->cleanupsHaveSideEffects()) {
       Diag(St->getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA;



More information about the cfe-commits mailing list