Skip to content

Commit 7e4c0f6

Browse files
committed
abtract attribute fallthrough
1 parent 4bd47bc commit 7e4c0f6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/common/tusb_compiler.h

+10
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
#define TU_ATTR_BIT_FIELD_ORDER_BEGIN
132132
#define TU_ATTR_BIT_FIELD_ORDER_END
133133

134+
#if __has_attribute(__fallthrough__)
135+
#define TU_ATTR_FALLTHROUGH __attribute__((fallthrough))
136+
#else
137+
#define TU_ATTR_FALLTHROUGH do {} while (0) /* fallthrough */
138+
#endif
139+
134140
// Endian conversion use well-known host to network (big endian) naming
135141
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
136142
#define TU_BYTE_ORDER TU_LITTLE_ENDIAN
@@ -156,6 +162,7 @@
156162
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
157163
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
158164
#define TU_ATTR_USED __attribute__ ((used))
165+
#define TU_ATTR_FALLTHROUGH __attribute__((fallthrough))
159166

160167
#define TU_ATTR_PACKED_BEGIN
161168
#define TU_ATTR_PACKED_END
@@ -182,6 +189,7 @@
182189
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
183190
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
184191
#define TU_ATTR_USED __attribute__ ((used)) // Function/Variable is meant to be used
192+
#define TU_ATTR_FALLTHROUGH __attribute__((fallthrough))
185193

186194
#define TU_ATTR_PACKED_BEGIN
187195
#define TU_ATTR_PACKED_END
@@ -207,6 +215,7 @@
207215
#define TU_ATTR_DEPRECATED(mess)
208216
#define TU_ATTR_UNUSED
209217
#define TU_ATTR_USED
218+
#define TU_ATTR_FALLTHROUGH do {} while (0) /* fallthrough */
210219

211220
#define TU_ATTR_PACKED_BEGIN _Pragma("pack")
212221
#define TU_ATTR_PACKED_END _Pragma("packoption")
@@ -227,6 +236,7 @@
227236
#error "Compiler attribute porting is required"
228237
#endif
229238

239+
230240
#if (TU_BYTE_ORDER == TU_LITTLE_ENDIAN)
231241

232242
#define tu_htons(u16) (TU_BSWAP16(u16))

src/host/usbh.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
655655
TU_ASSERT( hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), _ctrl_xfer.buffer, request->wLength) );
656656
return true;
657657
}
658-
#if __GNUC__ >= 7
659-
__attribute__((fallthrough));
660-
#endif
658+
TU_ATTR_FALLTHROUGH;
661659

662660
case CONTROL_STAGE_DATA:
663661
if (request->wLength)

0 commit comments

Comments
 (0)