Skip to content

Commit 2fc4698

Browse files
committed
Disable fallthrough attribute for older GCC
1 parent b7157d4 commit 2fc4698

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

core/kmod/llring.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
#ifndef _LLRING_H_
6767
#define _LLRING_H_
6868

69+
#if defined(__has_cpp_attribute)
70+
#if __has_cpp_attribute(fallthrough)
71+
#define FALLTHROUGH [[fallthrough]]
72+
#elif __has_cpp_attribute(clang::fallthrough)
73+
#define FALLTHROUGH [[clang::fallthrough]]
74+
#else
75+
#define FALLTHROUGH
76+
#endif
77+
#else
78+
#define FALLTHROUGH
79+
#endif
80+
6981
/**
7082
* Note: the ring implementation is not preemptable. A producer must not
7183
* be interrupted by another producer that uses the same ring.
@@ -327,10 +339,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
327339
switch (n & 0x3) { \
328340
case 3: \
329341
r->ring[idx++] = obj_table[i++]; \
330-
[[gnu::fallthrough]]; \
342+
FALLTHROUGH; \
331343
case 2: \
332344
r->ring[idx++] = obj_table[i++]; \
333-
[[gnu::fallthrough]]; \
345+
FALLTHROUGH; \
334346
case 1: \
335347
r->ring[idx++] = obj_table[i++]; \
336348
} \
@@ -360,10 +372,10 @@ static inline int llring_set_water_mark(struct llring *r, unsigned count)
360372
switch (n & 0x3) { \
361373
case 3: \
362374
obj_table[i++] = r->ring[idx++]; \
363-
[[gnu::fallthrough]]; \
375+
FALLTHROUGH; \
364376
case 2: \
365377
obj_table[i++] = r->ring[idx++]; \
366-
[[gnu::fallthrough]]; \
378+
FALLTHROUGH; \
367379
case 1: \
368380
obj_table[i++] = r->ring[idx++]; \
369381
} \

core/utils/copy.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#ifndef BESS_UTILS_COPY_H_
22
#define BESS_UTILS_COPY_H_
33

4+
#if defined(__has_cpp_attribute)
5+
#if __has_cpp_attribute(fallthrough)
6+
#define FALLTHROUGH [[fallthrough]]
7+
#elif __has_cpp_attribute(clang::fallthrough)
8+
#define FALLTHROUGH [[clang::fallthrough]]
9+
#else
10+
#define FALLTHROUGH
11+
#endif
12+
#else
13+
#define FALLTHROUGH
14+
#endif
15+
416
#include <glog/logging.h>
517
#include <x86intrin.h>
618

@@ -78,7 +90,7 @@ static inline void CopySmall(void *__restrict__ dst,
7890
break;
7991
case 9:
8092
memcpy(d + 8, s + 8, 1);
81-
[[gnu::fallthrough]];
93+
FALLTHROUGH;
8294
case 8:
8395
memcpy(d, s, 8);
8496
break;
@@ -91,13 +103,13 @@ static inline void CopySmall(void *__restrict__ dst,
91103
break;
92104
case 5:
93105
memcpy(d + 4, s + 4, 1);
94-
[[gnu::fallthrough]];
106+
FALLTHROUGH;
95107
case 4:
96108
memcpy(d, s, 4);
97109
break;
98110
case 3:
99111
memcpy(d + 2, s + 2, 1);
100-
[[gnu::fallthrough]];
112+
FALLTHROUGH;
101113
case 2:
102114
memcpy(d, s, 2);
103115
break;
@@ -171,22 +183,22 @@ static inline void CopyInlined(void *__restrict__ dst,
171183
switch (leftover_blocks) {
172184
case 7:
173185
copy_block(d + 6, s + 6);
174-
[[gnu::fallthrough]];
186+
FALLTHROUGH;
175187
case 6:
176188
copy_block(d + 5, s + 5);
177-
[[gnu::fallthrough]];
189+
FALLTHROUGH;
178190
case 5:
179191
copy_block(d + 4, s + 4);
180-
[[gnu::fallthrough]];
192+
FALLTHROUGH;
181193
case 4:
182194
copy_block(d + 3, s + 3);
183-
[[gnu::fallthrough]];
195+
FALLTHROUGH;
184196
case 3:
185197
copy_block(d + 2, s + 2);
186-
[[gnu::fallthrough]];
198+
FALLTHROUGH;
187199
case 2:
188200
copy_block(d + 1, s + 1);
189-
[[gnu::fallthrough]];
201+
FALLTHROUGH;
190202
case 1:
191203
copy_block(d + 0, s + 0);
192204
}

0 commit comments

Comments
 (0)