diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2019-02-21 00:01:02 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2019-02-21 00:01:02 +0000 |
commit | 4c12fc335614018800bef94556f09aa0a50e51c6 (patch) | |
tree | 37a307d0f409171f9d7642e23cbe288725ba5a43 /test | |
parent | c836e11927623cae953b4f601ce0a8f466e78dd8 (diff) |
[attributes] Add an attribute for server routines in Mach kernel and extensions.
The new __attribute__ ((mig_server_routine)) is going to be used for annotating
Mach Interface Generator (MIG) callback functions as such, so that additional
static analysis could be applied to their implementations. It can also be
applied to regular functions behavior of which is supposed to be identical to
that of a MIG server routine.
Differential Revision: https://reviews.llvm.org/D58365
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Misc/pragma-attribute-supported-attributes-list.test | 1 | ||||
-rw-r--r-- | test/Sema/attr-mig.c | 22 | ||||
-rw-r--r-- | test/Sema/attr-mig.cpp | 20 | ||||
-rw-r--r-- | test/Sema/attr-mig.m | 31 |
4 files changed, 74 insertions, 0 deletions
diff --git a/test/Misc/pragma-attribute-supported-attributes-list.test b/test/Misc/pragma-attribute-supported-attributes-list.test index 45012ae9bf..146642dd12 100644 --- a/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/test/Misc/pragma-attribute-supported-attributes-list.test @@ -61,6 +61,7 @@ // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record) // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record) // CHECK-NEXT: Lockable (SubjectMatchRule_record) +// CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function) // CHECK-NEXT: MSStruct (SubjectMatchRule_record) // CHECK-NEXT: MicroMips (SubjectMatchRule_function) // CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method) diff --git a/test/Sema/attr-mig.c b/test/Sema/attr-mig.c new file mode 100644 index 0000000000..3b16696cd7 --- /dev/null +++ b/test/Sema/attr-mig.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int kern_return_t; +#define KERN_SUCCESS 0 + +__attribute__((mig_server_routine)) kern_return_t var = KERN_SUCCESS; // expected-warning{{'mig_server_routine' attribute only applies to functions, Objective-C methods, and blocks}} + +__attribute__((mig_server_routine)) void foo_void(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +__attribute__((mig_server_routine)) int foo_int(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + +__attribute__((mig_server_routine)) kern_return_t bar_extern(); // no-warning +__attribute__((mig_server_routine)) kern_return_t bar_forward(); // no-warning + +__attribute__((mig_server_routine)) kern_return_t bar_definition() { // no-warning + return KERN_SUCCESS; +} + +kern_return_t bar_forward() { // no-warning + return KERN_SUCCESS; +} + +__attribute__((mig_server_routine(123))) kern_return_t bar_with_argument(); // expected-error{{'mig_server_routine' attribute takes no arguments}} diff --git a/test/Sema/attr-mig.cpp b/test/Sema/attr-mig.cpp new file mode 100644 index 0000000000..5dfc43bc1e --- /dev/null +++ b/test/Sema/attr-mig.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int kern_return_t; +typedef kern_return_t IOReturn; +#define KERN_SUCCESS 0 +#define kIOReturnSuccess KERN_SUCCESS + +class MyServer { +public: + virtual __attribute__((mig_server_routine)) IOReturn externalMethod(); + virtual __attribute__((mig_server_routine)) void anotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + virtual __attribute__((mig_server_routine)) int yetAnotherMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} + [[clang::mig_server_routine]] virtual IOReturn cppAnnotatedMethod(); + [[clang::mig_server_routine("arg")]] virtual IOReturn cppAnnotatedMethodWithInvalidArgs(); // expected-error{{'mig_server_routine' attribute takes no arguments}} + [[clang::mig_server_routine]] virtual int cppInvalidAnnotatedMethod(); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +}; + +IOReturn MyServer::externalMethod() { + return kIOReturnSuccess; +} diff --git a/test/Sema/attr-mig.m b/test/Sema/attr-mig.m new file mode 100644 index 0000000000..a40a9172e5 --- /dev/null +++ b/test/Sema/attr-mig.m @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s + +typedef int kern_return_t; +#define KERN_SUCCESS 0 + +@interface NSObject +@end + +@interface I: NSObject +- (kern_return_t)foo __attribute__((mig_server_routine)); // no-warning +- (void) bar_void __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +- (int) bar_int __attribute__((mig_server_routine)); // expected-warning{{'mig_server_routine' attribute only applies to routines that return a kern_return_t}} +@end + +@implementation I +- (kern_return_t)foo { + kern_return_t (^block)() = ^ __attribute__((mig_server_routine)) { // no-warning + return KERN_SUCCESS; + }; + + // FIXME: Warn that this block doesn't return a kern_return_t. + void (^invalid_block)() = ^ __attribute__((mig_server_routine)) {}; + + return block(); +} +- (void)bar_void { +} +- (int)bar_int { + return 0; +} +@end |