Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ Improvements to Clang's diagnostics
- Now correctly diagnose a tentative definition of an array with static
storage duration in pedantic mode in C. (#GH50661)

- The ``-err-musttail-mismatch`` error is emitted when a musttail call is made to a function marked with the not_tail_called attribute.(#133509).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The ``-err-musttail-mismatch`` error is emitted when a musttail call is made to a function marked with the not_tail_called attribute.(#133509).
- An error is now emitted when a ``musttail`` call is made to a function marked with the ``not_tail_called`` attribute. (#GH133509).



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should only be a single -new-line at the end of this list.

Improvements to Clang's time-trace
----------------------------------

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -3134,6 +3134,7 @@ def warn_function_attribute_ignored_in_stmt : Warning<
"use '%0' on statements">,
InGroup<IgnoredAttributes>;


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can back out this whitespace change.

def err_musttail_needs_trivial_args : Error<
"tail call requires that the return value, all parameters, and any "
"temporaries created by the expression are trivially destructible">;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
return false;
}

if (const FunctionDecl *CalleeDecl = CE->getDirectCallee();
CalleeDecl && CalleeDecl->hasAttr<NotTailCalledAttr>()) {
Diag(St->getBeginLoc(), diag::err_musttail_mismatch)
<< &MTA;
return false;
}

if (const auto *EWC = dyn_cast<ExprWithCleanups>(E)) {
if (EWC->cleanupsHaveSideEffects()) {
Diag(St->getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA;
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Sema/attr-musttail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -verify -fsyntax-only %s

int __attribute__((not_tail_called)) foo1(int a) {
return a + 1;
}


int foo2(int a) {
[[clang::musttail]]
return foo1(a); // expected-error{{cannot perform a tail call to function'musttail' because its signature is incompatible with the calling function}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diagnostic seems odd to me because of function'musttail' Is there really no whitespace there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diagnostic seems odd to me because of function'musttail' Is there really no whitespace there?

@AaronBallman Since we reuse err_musttail_mismatch, and the function itself does not have spaces, I tried to add spaces , but the test case did not pass.I've pasted the code below.

def err_musttail_mismatch : Error<
  "cannot perform a tail call to function%select{| %1}0 "
  "because its signature is incompatible with the calling function">;

}

int main() {
int result = foo2(10);
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the newline to the end of the file?