Skip to content

Commit 4a47011

Browse files
pabigotioannisg
authored andcommitted
arc: rearrange for standard use of extern "C"
Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Remove extern "C" support from files that don't declare objects or functions. In arch/arc/arch.h the extern "C" in the including context is left active during an include to avoid more complex restructuring. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot <[email protected]>
1 parent 20bb672 commit 4a47011

File tree

13 files changed

+62
-68
lines changed

13 files changed

+62
-68
lines changed

arch/arc/include/kernel_arch_data.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_DATA_H_
2121
#define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_DATA_H_
2222

23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
2723
#include <toolchain.h>
2824
#include <linker/sections.h>
2925
#include <arch/cpu.h>
@@ -36,9 +32,11 @@ extern "C" {
3632
#include <zephyr/types.h>
3733
#include <sys/util.h>
3834
#include <sys/dlist.h>
35+
36+
#ifdef __cplusplus
37+
extern "C" {
3938
#endif
4039

41-
#ifndef _ASMLANGUAGE
4240
#ifdef CONFIG_ARC_HAS_SECURE
4341
struct _irq_stack_frame {
4442
u32_t lp_end;
@@ -170,6 +168,10 @@ struct _callee_saved_stack {
170168

171169
typedef struct _callee_saved_stack _callee_saved_stack_t;
172170

171+
#ifdef __cplusplus
172+
}
173+
#endif
174+
173175
#endif /* _ASMLANGUAGE */
174176

175177
/* stacks */
@@ -179,8 +181,5 @@ typedef struct _callee_saved_stack _callee_saved_stack_t;
179181
#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE)
180182
#define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE)
181183

182-
#ifdef __cplusplus
183-
}
184-
#endif
185184

186185
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_DATA_H_ */

arch/arc/include/kernel_arch_func.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
#ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_
2121
#define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_
2222

23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
2723
#if !defined(_ASMLANGUAGE)
2824

2925
#ifdef CONFIG_CPU_ARCV2
3026
#include <v2/cache.h>
3127
#include <v2/irq.h>
3228
#endif
3329

30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
3434
static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void)
3535
{
3636
#ifdef CONFIG_SMP
@@ -80,10 +80,10 @@ extern void z_arc_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
8080

8181
extern void z_arch_sched_ipi(void);
8282

83-
#endif /* _ASMLANGUAGE */
84-
8583
#ifdef __cplusplus
8684
}
8785
#endif
8886

87+
#endif /* _ASMLANGUAGE */
88+
8989
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_ */

arch/arc/include/kernel_arch_thread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#ifndef _ASMLANGUAGE
3232
#include <zephyr/types.h>
3333

34+
#ifdef __cplusplus
35+
extern "C" {
36+
#endif
37+
3438
struct _callee_saved {
3539
u32_t sp; /* r28 */
3640
};
@@ -60,6 +64,11 @@ struct _thread_arch {
6064

6165
typedef struct _thread_arch _thread_arch_t;
6266

67+
#ifdef __cplusplus
68+
}
69+
#endif
70+
6371
#endif /* _ASMLANGUAGE */
6472

73+
6574
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_THREAD_H_ */

arch/arc/include/swap_macros.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include <toolchain.h>
1515
#include <arch/cpu.h>
1616

17-
#ifdef __cplusplus
18-
extern "C" {
19-
#endif
20-
2117
#ifdef _ASMLANGUAGE
2218

2319
/* entering this macro, current is in r2 */
@@ -338,8 +334,4 @@ extern "C" {
338334

339335
#endif /* _ASMLANGUAGE */
340336

341-
#ifdef __cplusplus
342-
}
343-
#endif
344-
345337
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_SWAP_MACROS_H_ */

arch/arc/include/v2/cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
#include <arch/cpu.h>
1919

20+
#ifndef _ASMLANGUAGE
21+
2022
#ifdef __cplusplus
2123
extern "C" {
2224
#endif
2325

24-
#ifndef _ASMLANGUAGE
25-
2626
/* i-cache defines for IC_CTRL register */
2727
#define IC_CACHE_ENABLE 0x00
2828
#define IC_CACHE_DISABLE 0x01
@@ -50,10 +50,10 @@ static ALWAYS_INLINE void z_icache_setup(void)
5050
}
5151
}
5252

53-
#endif /* _ASMLANGUAGE */
54-
5553
#ifdef __cplusplus
5654
}
5755
#endif
5856

57+
#endif /* _ASMLANGUAGE */
58+
5959
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_V2_CACHE_H_ */

arch/arc/include/vector_table.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#ifndef ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_
2222
#define ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_
2323

24-
#ifdef __cplusplus
25-
extern "C" {
26-
#endif
27-
2824
#define EXC_EV_TRAP 0x9
2925

3026
#ifdef _ASMLANGUAGE
@@ -55,6 +51,10 @@ GTEXT(_isr_wrapper)
5551

5652
#else
5753

54+
#ifdef __cplusplus
55+
extern "C" {
56+
#endif
57+
5858
extern void __reset(void);
5959
extern void __memory_error(void);
6060
extern void __instruction_error(void);
@@ -70,10 +70,10 @@ extern void __ev_div_zero(void);
7070
extern void __ev_dc_error(void);
7171
extern void __ev_maligned(void);
7272

73-
#endif /* _ASMLANGUAGE */
74-
7573
#ifdef __cplusplus
7674
}
7775
#endif
7876

77+
#endif /* _ASMLANGUAGE */
78+
7979
#endif /* ZEPHYR_ARCH_ARC_INCLUDE_VECTOR_TABLE_H_ */

include/arch/arc/arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ extern "C" {
160160

161161
#ifdef CONFIG_ARC_MPU
162162
#ifndef _ASMLANGUAGE
163+
164+
/* Legacy case: retain containing extern "C" with C++ */
163165
#include <arch/arc/v2/mpu/arc_mpu.h>
164166

165167
#define K_MEM_PARTITION_P_NA_U_NA AUX_MPU_ATTR_N

include/arch/arc/v2/arc_connect.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
#ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_
1515
#define ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_
1616

17+
#ifndef _ASMLANGUAGE
18+
#include <zephyr/types.h>
1719

1820
#ifdef __cplusplus
1921
extern "C" {
2022
#endif
2123

22-
#ifndef _ASMLANGUAGE
23-
#include <zephyr/types.h>
24-
2524
#define _ARC_V2_CONNECT_BCR 0x0d0
2625
#define _ARC_V2_CONNECT_IDU_BCR 0x0d5
2726
#define _ARC_V2_CONNECT_GFRC_BCR 0x0d6
@@ -227,9 +226,10 @@ extern void z_arc_connect_idu_set_mask(u32_t irq_num, u32_t mask);
227226
extern u32_t z_arc_connect_idu_read_mask(u32_t irq_num);
228227
extern u32_t z_arc_connect_idu_check_first(u32_t irq_num);
229228

230-
#endif
231-
232229
#ifdef __cplusplus
233230
}
234231
#endif
232+
233+
#endif /* _ASMLANGUAGE */
234+
235235
#endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_ARC_CONNECT_H_ */

include/arch/arc/v2/asm_inline_gcc.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,25 @@
99
#ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_
1010
#define ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_
1111

12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif
15-
1612
#ifndef _ASMLANGUAGE
1713

1814
#include <zephyr/types.h>
1915
#include <stddef.h>
2016

17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
2122
/**
2223
* @brief read timestamp register (CPU frequency)
2324
*/
2425
extern u64_t z_tsc_read(void);
2526

26-
27-
28-
#endif /* _ASMLANGUAGE */
29-
3027
#ifdef __cplusplus
3128
}
3229
#endif
3330

31+
#endif /* _ASMLANGUAGE */
32+
3433
#endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_ASM_INLINE_GCC_H_ */

include/arch/arc/v2/aux_regs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_
1616
#define ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_
1717

18-
#ifdef __cplusplus
19-
extern "C" {
20-
#endif
21-
2218
#define _ARC_V2_LP_START 0x002
2319
#define _ARC_V2_LP_END 0x003
2420
#define _ARC_V2_IDENTITY 0x004
@@ -201,8 +197,4 @@ extern "C" {
201197
__ret; \
202198
})
203199

204-
#ifdef __cplusplus
205-
}
206-
#endif
207-
208200
#endif /* ZEPHYR_INCLUDE_ARCH_ARC_V2_AUX_REGS_H_ */

0 commit comments

Comments
 (0)