Files
clang-p2996/clang/test/Sema/attr-musttail.m
Joshua Haberman 8344675908 Implemented [[clang::musttail]] attribute for guaranteed tail calls.
This is a Clang-only change and depends on the existing "musttail"
support already implemented in LLVM.

The [[clang::musttail]] attribute goes on a return statement, not
a function definition. There are several constraints that the user
must follow when using [[clang::musttail]], and these constraints
are verified by Sema.

Tail calls are supported on regular function calls, calls through a
function pointer, member function calls, and even pointer to member.

Future work would be to throw a warning if a users tries to pass
a pointer or reference to a local variable through a musttail call.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D99517
2021-04-15 17:12:21 -07:00

27 lines
857 B
Objective-C

// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -verify %s
void TestObjcBlock(void) {
void (^x)(void) = ^(void) {
__attribute__((musttail)) return TestObjcBlock(); // expected-error{{'musttail' attribute cannot be used from a block}}
};
__attribute__((musttail)) return x();
}
void ReturnsVoid(void);
void TestObjcBlockVar(void) {
__block int i = 0; // expected-note{{jump exits scope of __block variable}}
__attribute__((musttail)) return ReturnsVoid(); // expected-error{{cannot perform a tail call from this return statement}}
}
__attribute__((objc_root_class))
@interface TestObjcClass
@end
@implementation TestObjcClass
- (void)testObjCMethod {
__attribute__((musttail)) return ReturnsVoid(); // expected-error{{'musttail' attribute cannot be used from an Objective-C function}}
}
@end