Skip to content

Commit 28acee4

Browse files
committed
Report error when a musttail call is made to a function marked with the not_tail_called attribute
1 parent bf4921f commit 28acee4

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ Improvements to Clang's diagnostics
325325
- Now correctly diagnose a tentative definition of an array with static
326326
storage duration in pedantic mode in C. (#GH50661)
327327

328+
- The ``-err-musttail-mismatch`` error is emitted when a musttail call is made to a function marked with the not_tail_called attribute.(#133509).
329+
330+
328331
Improvements to Clang's time-trace
329332
----------------------------------
330333

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,9 +3134,7 @@ def warn_function_attribute_ignored_in_stmt : Warning<
31343134
"use '%0' on statements">,
31353135
InGroup<IgnoredAttributes>;
31363136

3137-
def err_musttail_conflicts_with_not_tail_called : Error<
3138-
"%0 musttail conflicts with not tail called"
3139-
>;
3137+
31403138
def err_musttail_needs_trivial_args : Error<
31413139
"tail call requires that the return value, all parameters, and any "
31423140
"temporaries created by the expression are trivially destructible">;

clang/lib/Sema/SemaStmt.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,11 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
717717
return false;
718718
}
719719

720-
if (const FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
721-
if (CalleeDecl->hasAttr<NotTailCalledAttr>()) {
722-
Diag(St->getBeginLoc(), diag::err_musttail_conflicts_with_not_tail_called)
723-
<< &MTA;
724-
return false;
725-
}
720+
if (const FunctionDecl *CalleeDecl = CE->getDirectCallee();
721+
CalleeDecl && CalleeDecl->hasAttr<NotTailCalledAttr>()) {
722+
Diag(St->getBeginLoc(), diag::err_musttail_mismatch)
723+
<< &MTA;
724+
return false;
726725
}
727726

728727
if (const auto *EWC = dyn_cast<ExprWithCleanups>(E)) {

clang/test/Sema/attr-musttail.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only %s
2+
3+
int __attribute__((not_tail_called)) foo1(int a) {
4+
return a + 1;
5+
}
6+
7+
8+
int foo2(int a) {
9+
[[clang::musttail]]
10+
return foo1(a); // expected-error{{cannot perform a tail call to function'musttail' because its signature is incompatible with the calling function}}
11+
}
12+
13+
int main() {
14+
int result = foo2(10);
15+
return 0;
16+
}

0 commit comments

Comments
 (0)