TESTS/mbedmicro-mbed/attributes/attributes.c@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | #include "toolchain.h" |
nexpaq | 0:6c56fb4bc5f0 | 2 | |
nexpaq | 0:6c56fb4bc5f0 | 3 | #include <stdio.h> |
nexpaq | 0:6c56fb4bc5f0 | 4 | #include <stdint.h> |
nexpaq | 0:6c56fb4bc5f0 | 5 | |
nexpaq | 0:6c56fb4bc5f0 | 6 | |
nexpaq | 0:6c56fb4bc5f0 | 7 | MBED_PACKED(struct) TestAttrPackedStruct1 { |
nexpaq | 0:6c56fb4bc5f0 | 8 | char a; |
nexpaq | 0:6c56fb4bc5f0 | 9 | int x; |
nexpaq | 0:6c56fb4bc5f0 | 10 | }; |
nexpaq | 0:6c56fb4bc5f0 | 11 | |
nexpaq | 0:6c56fb4bc5f0 | 12 | typedef MBED_PACKED(struct) { |
nexpaq | 0:6c56fb4bc5f0 | 13 | char a; |
nexpaq | 0:6c56fb4bc5f0 | 14 | int x; |
nexpaq | 0:6c56fb4bc5f0 | 15 | } TestAttrPackedStruct2; |
nexpaq | 0:6c56fb4bc5f0 | 16 | |
nexpaq | 0:6c56fb4bc5f0 | 17 | int testPacked() { |
nexpaq | 0:6c56fb4bc5f0 | 18 | int failed = 0; |
nexpaq | 0:6c56fb4bc5f0 | 19 | |
nexpaq | 0:6c56fb4bc5f0 | 20 | if (sizeof(struct TestAttrPackedStruct1) != sizeof(int) + sizeof(char)) { |
nexpaq | 0:6c56fb4bc5f0 | 21 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 22 | } |
nexpaq | 0:6c56fb4bc5f0 | 23 | |
nexpaq | 0:6c56fb4bc5f0 | 24 | if (sizeof(TestAttrPackedStruct2) != sizeof(int) + sizeof(char)) { |
nexpaq | 0:6c56fb4bc5f0 | 25 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 26 | } |
nexpaq | 0:6c56fb4bc5f0 | 27 | |
nexpaq | 0:6c56fb4bc5f0 | 28 | return failed; |
nexpaq | 0:6c56fb4bc5f0 | 29 | } |
nexpaq | 0:6c56fb4bc5f0 | 30 | |
nexpaq | 0:6c56fb4bc5f0 | 31 | |
nexpaq | 0:6c56fb4bc5f0 | 32 | MBED_ALIGN(8) char a; |
nexpaq | 0:6c56fb4bc5f0 | 33 | MBED_ALIGN(8) char b; |
nexpaq | 0:6c56fb4bc5f0 | 34 | MBED_ALIGN(16) char c; |
nexpaq | 0:6c56fb4bc5f0 | 35 | MBED_ALIGN(8) char d; |
nexpaq | 0:6c56fb4bc5f0 | 36 | MBED_ALIGN(16) char e; |
nexpaq | 0:6c56fb4bc5f0 | 37 | |
nexpaq | 0:6c56fb4bc5f0 | 38 | int testAlign() { |
nexpaq | 0:6c56fb4bc5f0 | 39 | int failed = 0; |
nexpaq | 0:6c56fb4bc5f0 | 40 | |
nexpaq | 0:6c56fb4bc5f0 | 41 | if(((uintptr_t)&a) & 0x7){ |
nexpaq | 0:6c56fb4bc5f0 | 42 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 43 | } |
nexpaq | 0:6c56fb4bc5f0 | 44 | if(((uintptr_t)&b) & 0x7){ |
nexpaq | 0:6c56fb4bc5f0 | 45 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 46 | } |
nexpaq | 0:6c56fb4bc5f0 | 47 | if(((uintptr_t)&c) & 0xf){ |
nexpaq | 0:6c56fb4bc5f0 | 48 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 49 | } |
nexpaq | 0:6c56fb4bc5f0 | 50 | if(((uintptr_t)&d) & 0x7){ |
nexpaq | 0:6c56fb4bc5f0 | 51 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 52 | } |
nexpaq | 0:6c56fb4bc5f0 | 53 | if(((uintptr_t)&e) & 0xf){ |
nexpaq | 0:6c56fb4bc5f0 | 54 | failed++; |
nexpaq | 0:6c56fb4bc5f0 | 55 | } |
nexpaq | 0:6c56fb4bc5f0 | 56 | |
nexpaq | 0:6c56fb4bc5f0 | 57 | return failed; |
nexpaq | 0:6c56fb4bc5f0 | 58 | } |
nexpaq | 0:6c56fb4bc5f0 | 59 | |
nexpaq | 0:6c56fb4bc5f0 | 60 | |
nexpaq | 0:6c56fb4bc5f0 | 61 | int testUnused1(MBED_UNUSED int arg) { |
nexpaq | 0:6c56fb4bc5f0 | 62 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 63 | } |
nexpaq | 0:6c56fb4bc5f0 | 64 | |
nexpaq | 0:6c56fb4bc5f0 | 65 | int testUnused() { |
nexpaq | 0:6c56fb4bc5f0 | 66 | return testUnused1(0); |
nexpaq | 0:6c56fb4bc5f0 | 67 | } |
nexpaq | 0:6c56fb4bc5f0 | 68 | |
nexpaq | 0:6c56fb4bc5f0 | 69 | |
nexpaq | 0:6c56fb4bc5f0 | 70 | int testWeak1(); |
nexpaq | 0:6c56fb4bc5f0 | 71 | int testWeak2(); |
nexpaq | 0:6c56fb4bc5f0 | 72 | |
nexpaq | 0:6c56fb4bc5f0 | 73 | MBED_WEAK int testWeak1() { |
nexpaq | 0:6c56fb4bc5f0 | 74 | return 1; |
nexpaq | 0:6c56fb4bc5f0 | 75 | } |
nexpaq | 0:6c56fb4bc5f0 | 76 | |
nexpaq | 0:6c56fb4bc5f0 | 77 | int testWeak2() { |
nexpaq | 0:6c56fb4bc5f0 | 78 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 79 | } |
nexpaq | 0:6c56fb4bc5f0 | 80 | |
nexpaq | 0:6c56fb4bc5f0 | 81 | int testWeak() { |
nexpaq | 0:6c56fb4bc5f0 | 82 | return testWeak1() | testWeak2(); |
nexpaq | 0:6c56fb4bc5f0 | 83 | } |
nexpaq | 0:6c56fb4bc5f0 | 84 | |
nexpaq | 0:6c56fb4bc5f0 | 85 | |
nexpaq | 0:6c56fb4bc5f0 | 86 | MBED_PURE int testPure1() { |
nexpaq | 0:6c56fb4bc5f0 | 87 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 88 | } |
nexpaq | 0:6c56fb4bc5f0 | 89 | |
nexpaq | 0:6c56fb4bc5f0 | 90 | int testPure() { |
nexpaq | 0:6c56fb4bc5f0 | 91 | return testPure1(); |
nexpaq | 0:6c56fb4bc5f0 | 92 | } |
nexpaq | 0:6c56fb4bc5f0 | 93 | |
nexpaq | 0:6c56fb4bc5f0 | 94 | |
nexpaq | 0:6c56fb4bc5f0 | 95 | MBED_FORCEINLINE int testForceInline1() { |
nexpaq | 0:6c56fb4bc5f0 | 96 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 97 | } |
nexpaq | 0:6c56fb4bc5f0 | 98 | |
nexpaq | 0:6c56fb4bc5f0 | 99 | int testForceInline() { |
nexpaq | 0:6c56fb4bc5f0 | 100 | return testForceInline1(); |
nexpaq | 0:6c56fb4bc5f0 | 101 | } |
nexpaq | 0:6c56fb4bc5f0 | 102 | |
nexpaq | 0:6c56fb4bc5f0 | 103 | |
nexpaq | 0:6c56fb4bc5f0 | 104 | MBED_NORETURN int testNoReturn1() { |
nexpaq | 0:6c56fb4bc5f0 | 105 | while (1) {} |
nexpaq | 0:6c56fb4bc5f0 | 106 | } |
nexpaq | 0:6c56fb4bc5f0 | 107 | |
nexpaq | 0:6c56fb4bc5f0 | 108 | int testNoReturn() { |
nexpaq | 0:6c56fb4bc5f0 | 109 | if (0) { |
nexpaq | 0:6c56fb4bc5f0 | 110 | testNoReturn1(); |
nexpaq | 0:6c56fb4bc5f0 | 111 | } |
nexpaq | 0:6c56fb4bc5f0 | 112 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 113 | } |
nexpaq | 0:6c56fb4bc5f0 | 114 | |
nexpaq | 0:6c56fb4bc5f0 | 115 | |
nexpaq | 0:6c56fb4bc5f0 | 116 | int testUnreachable1(int i) { |
nexpaq | 0:6c56fb4bc5f0 | 117 | switch (i) { |
nexpaq | 0:6c56fb4bc5f0 | 118 | case 0: |
nexpaq | 0:6c56fb4bc5f0 | 119 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 120 | } |
nexpaq | 0:6c56fb4bc5f0 | 121 | |
nexpaq | 0:6c56fb4bc5f0 | 122 | MBED_UNREACHABLE; |
nexpaq | 0:6c56fb4bc5f0 | 123 | } |
nexpaq | 0:6c56fb4bc5f0 | 124 | |
nexpaq | 0:6c56fb4bc5f0 | 125 | int testUnreachable() { |
nexpaq | 0:6c56fb4bc5f0 | 126 | return testUnreachable1(0); |
nexpaq | 0:6c56fb4bc5f0 | 127 | } |
nexpaq | 0:6c56fb4bc5f0 | 128 | |
nexpaq | 0:6c56fb4bc5f0 | 129 | |
nexpaq | 0:6c56fb4bc5f0 | 130 | MBED_DEPRECATED("this message should not be displayed") |
nexpaq | 0:6c56fb4bc5f0 | 131 | void testDeprecatedUnused(); |
nexpaq | 0:6c56fb4bc5f0 | 132 | void testDeprecatedUnused() { } |
nexpaq | 0:6c56fb4bc5f0 | 133 | |
nexpaq | 0:6c56fb4bc5f0 | 134 | MBED_DEPRECATED("this message should be displayed") |
nexpaq | 0:6c56fb4bc5f0 | 135 | int testDeprecatedUsed(); |
nexpaq | 0:6c56fb4bc5f0 | 136 | int testDeprecatedUsed() { |
nexpaq | 0:6c56fb4bc5f0 | 137 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 138 | } |
nexpaq | 0:6c56fb4bc5f0 | 139 | |
nexpaq | 0:6c56fb4bc5f0 | 140 | MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should not be displayed") |
nexpaq | 0:6c56fb4bc5f0 | 141 | void testDeprecatedSinceUnused(); |
nexpaq | 0:6c56fb4bc5f0 | 142 | void testDeprecatedSinceUnused() { } |
nexpaq | 0:6c56fb4bc5f0 | 143 | |
nexpaq | 0:6c56fb4bc5f0 | 144 | MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should be displayed") |
nexpaq | 0:6c56fb4bc5f0 | 145 | int testDeprecatedSinceUsed(); |
nexpaq | 0:6c56fb4bc5f0 | 146 | int testDeprecatedSinceUsed() { |
nexpaq | 0:6c56fb4bc5f0 | 147 | return 0; |
nexpaq | 0:6c56fb4bc5f0 | 148 | } |
nexpaq | 0:6c56fb4bc5f0 | 149 | |
nexpaq | 0:6c56fb4bc5f0 | 150 | int testDeprecated() { |
nexpaq | 0:6c56fb4bc5f0 | 151 | return testDeprecatedUsed() + testDeprecatedSinceUsed(); |
nexpaq | 0:6c56fb4bc5f0 | 152 | } |
nexpaq | 0:6c56fb4bc5f0 | 153 |