Skip to content

Commit 11d70c6

Browse files
thugheskartben
authored andcommitted
everywhere: Replace diagnostic pragmas with TOOLCHAIN_* macros
The TOOLCHAIN_DISABLE_WARNING/TOOLCHAIN_ENABLE_WARNING macros are easier to read and compiler agnostic. Signed-off-by: Tom Hughes <[email protected]>
1 parent 6f6d6d0 commit 11d70c6

File tree

18 files changed

+71
-133
lines changed

18 files changed

+71
-133
lines changed

arch/arm/core/cortex_a_r/reboot.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ static inline void relocate_vector_table(void)
2828

2929
#else
3030

31-
#if defined(__GNUC__)
3231
/*
3332
* GCC can detect if memcpy is passed a NULL argument, however one of
3433
* the cases of relocate_vector_table() it is valid to pass NULL, so we
3534
* suppress the warning for this case. We need to do this before
3635
* string.h is included to get the declaration of memcpy.
3736
*/
38-
#pragma GCC diagnostic push
39-
#pragma GCC diagnostic ignored "-Wnonnull"
40-
#endif /* __GNUC__ */
37+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)
4138

4239
#include <string.h>
4340

@@ -53,9 +50,7 @@ void __weak relocate_vector_table(void)
5350
#endif
5451
}
5552

56-
#if defined(__GNUC__)
57-
#pragma GCC diagnostic pop
58-
#endif
53+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)
5954

6055
#endif /* !CONFIG_AARCH32_ARMV8_R */
6156

arch/arm/core/cortex_m/prep_c.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
#include <zephyr/platform/hooks.h>
2424
#include <zephyr/arch/cache.h>
2525

26-
#if defined(__GNUC__)
2726
/*
2827
* GCC can detect if memcpy is passed a NULL argument, however one of
2928
* the cases of relocate_vector_table() it is valid to pass NULL, so we
3029
* suppress the warning for this case. We need to do this before
3130
* string.h is included to get the declaration of memcpy.
3231
*/
33-
#pragma GCC diagnostic push
34-
#pragma GCC diagnostic ignored "-Wnonnull"
35-
#endif
32+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)
3633

3734
#include <string.h>
3835

@@ -72,9 +69,7 @@ void __weak relocate_vector_table(void)
7269
#endif
7370
}
7471

75-
#if defined(__GNUC__)
76-
#pragma GCC diagnostic pop
77-
#endif
72+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_NONNULL)
7873

7974
#endif /* CONFIG_CPU_CORTEX_M_HAS_VTOR */
8075

drivers/dma/dma_xilinx_axi_dma.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ uint32_t dma_xilinx_axi_dma_last_received_frame_length(const struct device *dev)
359359
return data->channels[XILINX_AXI_DMA_RX_CHANNEL_NUM].last_rx_size;
360360
}
361361

362-
#pragma GCC diagnostic push
363-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
362+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER)
364363
static inline void
365364
dma_xilinx_axi_dma_acknowledge_interrupt(struct dma_xilinx_axi_dma_channel *channel_data)
366365
{
@@ -371,10 +370,9 @@ dma_xilinx_axi_dma_acknowledge_interrupt(struct dma_xilinx_axi_dma_channel *chan
371370

372371
dma_xilinx_axi_dma_write_reg(&channel_data->channel_regs->dmacr, dmacr);
373372
}
374-
#pragma GCC diagnostic pop
373+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER)
375374

376-
#pragma GCC diagnostic push
377-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
375+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER)
378376
static bool dma_xilinx_axi_dma_channel_has_error(
379377
const struct dma_xilinx_axi_dma_channel *channel_data,
380378
volatile const struct dma_xilinx_axi_dma_sg_descriptor *descriptor)
@@ -441,7 +439,7 @@ static bool dma_xilinx_axi_dma_channel_has_error(
441439

442440
return error;
443441
}
444-
#pragma GCC diagnostic pop
442+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER)
445443

446444
static int
447445
dma_xilinx_axi_dma_clean_up_sg_descriptors(const struct device *dev,
@@ -522,12 +520,11 @@ dma_xilinx_axi_dma_clean_up_sg_descriptors(const struct device *dev,
522520
processed_packets++;
523521
}
524522

525-
#pragma GCC diagnostic push
526-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
523+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
527524
/* this clears the IRQ */
528525
/* FIXME write the same value back... */
529526
dma_xilinx_axi_dma_write_reg(&channel_data->channel_regs->dmasr, 0xffffffff);
530-
#pragma GCC diagnostic pop
527+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
531528

532529
/* writes must commit before returning from ISR */
533530
barrier_dmem_fence_full();
@@ -615,8 +612,7 @@ static int dma_xilinx_axi_dma_start(const struct device *dev, uint32_t channel)
615612
channel == XILINX_AXI_DMA_TX_CHANNEL_NUM ? "TX" : "RX", tail_descriptor,
616613
channel_data->current_transfer_end_index);
617614

618-
#pragma GCC diagnostic push
619-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
615+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
620616
if (dma_xilinx_axi_dma_read_reg(&channel_data->channel_regs->dmasr) &
621617
XILINX_AXI_DMA_REGS_DMASR_HALTED) {
622618

@@ -636,7 +632,7 @@ static int dma_xilinx_axi_dma_start(const struct device *dev, uint32_t channel)
636632
(uint32_t)(uintptr_t)first_unprocessed_descriptor);
637633
#endif
638634
}
639-
#pragma GCC diagnostic pop
635+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
640636

641637
/* current descriptor MUST be set before tail descriptor */
642638
barrier_dmem_fence_full();
@@ -669,8 +665,7 @@ static int dma_xilinx_axi_dma_start(const struct device *dev, uint32_t channel)
669665

670666
LOG_DBG("New DMACR value: %" PRIx32, new_control);
671667

672-
#pragma GCC diagnostic push
673-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
668+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
674669
dma_xilinx_axi_dma_write_reg(&channel_data->channel_regs->dmacr, new_control);
675670
/* need to make sure start was committed before writing tail */
676671
barrier_dmem_fence_full();
@@ -685,7 +680,7 @@ static int dma_xilinx_axi_dma_start(const struct device *dev, uint32_t channel)
685680
dma_xilinx_axi_dma_write_reg(&channel_data->channel_regs->taildesc,
686681
(uint32_t)(uintptr_t)current_descriptor);
687682
#endif
688-
#pragma GCC diagnostic pop
683+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
689684

690685
dma_xilinx_axi_dma_enable_cache();
691686

@@ -717,10 +712,9 @@ static int dma_xilinx_axi_dma_stop(const struct device *dev, uint32_t channel)
717712
/* RS = 0 --> DMA will complete ongoing transactions and then go into hold */
718713
new_control = new_control & ~XILINX_AXI_DMA_REGS_DMACR_RS;
719714

720-
#pragma GCC diagnostic push
721-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
715+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
722716
dma_xilinx_axi_dma_write_reg(&channel_data->channel_regs->dmacr, new_control);
723-
#pragma GCC diagnostic pop
717+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
724718

725719
/* commit before returning to caller */
726720
barrier_dmem_fence_full();
@@ -743,13 +737,12 @@ static int dma_xilinx_axi_dma_get_status(const struct device *dev, uint32_t chan
743737

744738
memset(stat, 0, sizeof(*stat));
745739

746-
#pragma GCC diagnostic push
747-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
740+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
748741
stat->busy = !(dma_xilinx_axi_dma_read_reg(&channel_data->channel_regs->dmasr) &
749742
XILINX_AXI_DMA_REGS_DMASR_IDLE) &&
750743
!(dma_xilinx_axi_dma_read_reg(&channel_data->channel_regs->dmasr) &
751744
XILINX_AXI_DMA_REGS_DMASR_HALTED);
752-
#pragma GCC diagnostic pop
745+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
753746
stat->dir = channel_data->last_transfer_direction;
754747

755748
/* FIXME fill hardware-specific fields */
@@ -944,14 +937,13 @@ static int dma_xilinx_axi_dma_configure(const struct device *dev, uint32_t chann
944937

945938
if (!data->device_has_been_reset) {
946939
LOG_INF("Soft-resetting the DMA core!");
947-
#pragma GCC diagnostic push
948-
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
940+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
949941
/* this resets BOTH RX and TX channels, although it is triggered in per-channel
950942
* DMACR
951943
*/
952944
dma_xilinx_axi_dma_write_reg(&data->channels[channel].channel_regs->dmacr,
953945
XILINX_AXI_DMA_REGS_DMACR_RESET);
954-
#pragma GCC diagnostic pop
946+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER);
955947
data->device_has_been_reset = true;
956948
}
957949

include/zephyr/arch/arm/irq.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,12 @@ static inline void arch_isr_direct_footer(int maybe_swap)
169169
}
170170
}
171171

172-
#if defined(__clang__)
173172
#define ARCH_ISR_DIAG_OFF \
174-
_Pragma("clang diagnostic push") \
175-
_Pragma("clang diagnostic ignored \"-Wextra\"")
176-
#define ARCH_ISR_DIAG_ON _Pragma("clang diagnostic pop")
177-
#elif defined(__GNUC__)
178-
#define ARCH_ISR_DIAG_OFF \
179-
_Pragma("GCC diagnostic push") \
180-
_Pragma("GCC diagnostic ignored \"-Wattributes\"")
181-
#define ARCH_ISR_DIAG_ON _Pragma("GCC diagnostic pop")
182-
#else
183-
#define ARCH_ISR_DIAG_OFF
184-
#define ARCH_ISR_DIAG_ON
185-
#endif
173+
TOOLCHAIN_DISABLE_CLANG_WARNING(TOOLCHAIN_WARNING_EXTRA) \
174+
TOOLCHAIN_DISABLE_GCC_WARNING(TOOLCHAIN_WARNING_ATTRIBUTES)
175+
#define ARCH_ISR_DIAG_ON \
176+
TOOLCHAIN_ENABLE_CLANG_WARNING(TOOLCHAIN_WARNING_EXTRA) \
177+
TOOLCHAIN_ENABLE_GCC_WARNING(TOOLCHAIN_WARNING_ATTRIBUTES)
186178

187179
#define ARCH_ISR_DIRECT_DECLARE(name) \
188180
static inline int name##_body(void); \

include/zephyr/logging/log_core.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,9 @@ static inline char z_log_minimal_level_to_char(int level)
262262
GET_ARG_N(1, __VA_ARGS__))
263263

264264
#define LOG_POINTERS_VALIDATE(string_ok, ...) \
265-
_Pragma("GCC diagnostic push") \
266-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
265+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
267266
string_ok = Z_CBPRINTF_POINTERS_VALIDATE(__VA_ARGS__); \
268-
_Pragma("GCC diagnostic pop")
267+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
269268
#else
270269
#define LOG_POINTERS_VALIDATE(string_ok, ...) string_ok = true
271270
#define LOG_STRING_WARNING(_mode, _src, ...)

include/zephyr/logging/log_msg.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,9 @@ do { \
569569
#define Z_LOG_MSG_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source, \
570570
_level, _data, _dlen, ...) \
571571
do { \
572-
_Pragma("GCC diagnostic push") \
573-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
572+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
574573
FOR_EACH_IDX(Z_LOG_LOCAL_ARG_CREATE, (;), __VA_ARGS__); \
575-
_Pragma("GCC diagnostic pop") \
574+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
576575
Z_LOG_MSG_CREATE3(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\
577576
_level, _data, _dlen, \
578577
FOR_EACH_IDX(Z_LOG_LOCAL_ARG_NAME, (,), __VA_ARGS__)); \

include/zephyr/sys/cbprintf_cxx.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ template < typename T >
8181
static inline int z_cbprintf_cxx_is_pchar(T arg, bool const_as_fixed)
8282
{
8383
ARG_UNUSED(arg);
84-
_Pragma("GCC diagnostic push")
85-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
84+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
8685
ARG_UNUSED(const_as_fixed);
8786
return 0;
88-
_Pragma("GCC diagnostic pop")
87+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
8988
}
9089

9190
/* C++ version for determining if variable type is numeric and fits in 32 bit word. */
@@ -133,10 +132,9 @@ template < typename T >
133132
static inline int z_cbprintf_cxx_is_word_num(T arg)
134133
{
135134
ARG_UNUSED(arg);
136-
_Pragma("GCC diagnostic push")
137-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
135+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
138136
return 0;
139-
_Pragma("GCC diagnostic pop")
137+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
140138
}
141139

142140
/* C++ version for determining if argument is a none character pointer. */

include/zephyr/sys/cbprintf_internal.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,14 @@ extern "C" {
530530
*/
531531
#if Z_C_GENERIC
532532
#define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) ({\
533-
_Pragma("GCC diagnostic push") \
534-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
533+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
535534
int _rv; \
536535
if ((flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS) { \
537536
_rv = 0; \
538537
} else { \
539538
_rv = Z_CBPRINTF_PCHAR_COUNT(flags, __VA_ARGS__) > 0 ? 1 : 0; \
540539
} \
541-
_Pragma("GCC diagnostic pop")\
540+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
542541
_rv; \
543542
})
544543
#else
@@ -722,7 +721,6 @@ do { \
722721
#define Z_CBPRINTF_PACK_ARG(arg_idx, arg) \
723722
Z_CBPRINTF_PACK_ARG2(arg_idx, _pbuf, _pkg_len, _pkg_offset, _pmax, arg)
724723

725-
726724
/* Allocation to avoid using VLA and alloca. Alloc frees space when leaving
727725
* a function which can lead to increased stack usage if logging is used
728726
* multiple times. VLA is not always available.
@@ -767,8 +765,7 @@ do { \
767765
#define Z_CBPRINTF_STATIC_PACKAGE_GENERIC(buf, _inlen, _outlen, _align_offset, \
768766
flags, ... /* fmt, ... */) \
769767
do { \
770-
_Pragma("GCC diagnostic push") \
771-
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \
768+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
772769
BUILD_ASSERT(!IS_ENABLED(CONFIG_XTENSA) || \
773770
(IS_ENABLED(CONFIG_XTENSA) && \
774771
!((_align_offset) % CBPRINTF_PACKAGE_ALIGNMENT)), \
@@ -846,7 +843,7 @@ do { \
846843
(pkg_hdr.desc.pkg_flags = flags)); \
847844
*_len_loc = pkg_hdr; \
848845
} \
849-
_Pragma("GCC diagnostic pop") \
846+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
850847
} while (false)
851848

852849
#if Z_C_GENERIC

modules/thrift/src/thrift/server/TServerFramework.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ void TServerFramework::newlyConnectedClient(const shared_ptr<TConnectedClient> &
236236
onClientConnected(pClient);
237237
}
238238

239-
#pragma GCC diagnostic push
240-
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
239+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR)
241240
void TServerFramework::disposeConnectedClient(TConnectedClient *pClient)
242241
{
243242
onClientDisconnected(pClient);
@@ -248,7 +247,7 @@ void TServerFramework::disposeConnectedClient(TConnectedClient *pClient)
248247
// mon_.notify();
249248
}
250249
}
251-
#pragma GCC diagnostic pop
250+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR)
252251

253252
} // namespace server
254253
} // namespace thrift

tests/kernel/fatal/exception/src/main.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/ztest.h>
99
#include <zephyr/tc_util.h>
10+
#include <zephyr/test_toolchain.h>
1011
#include <zephyr/kernel_structs.h>
1112
#include <zephyr/irq_offload.h>
1213
#include <kswap.h>
@@ -192,20 +193,16 @@ __no_optimization void blow_up_stack(void)
192193
/* stack sentinel doesn't catch it in time before it trashes the entire kernel
193194
*/
194195

195-
#if defined(__GNUC__)
196-
#pragma GCC diagnostic push
197-
#pragma GCC diagnostic ignored "-Wpragmas"
198-
#pragma GCC diagnostic ignored "-Winfinite-recursion"
199-
#endif
196+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_PRAGMAS)
197+
TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_INFINITE_RECURSION)
200198

201199
__no_optimization int stack_smasher(int val)
202200
{
203201
return stack_smasher(val * 2) + stack_smasher(val * 3);
204202
}
205203

206-
#if defined(__GNUC__)
207-
#pragma GCC diagnostic pop
208-
#endif
204+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_PRAGMAS)
205+
TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_INFINITE_RECURSION)
209206

210207
void blow_up_stack(void)
211208
{

0 commit comments

Comments
 (0)