diff --git a/module/zfs/spa.c b/module/zfs/spa.c index eab444fa572..790bfee498a 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -4867,8 +4867,25 @@ spa_load_chain_map(spa_t *spa) KM_SLEEP); for (zap_cursor_init(&zc, os, chain_map_zap); zap_cursor_retrieve(&zc, &attr) == 0; zap_cursor_advance(&zc)) { + + /* + * Workaround for GCC 12+ with UBSan enabled deficencies. + * + * GCC 12+ invoked with -fsanitize=undefined incorrectly reports the code + * below as violating -Warray-bounds + */ +#if defined(__GNUC__) && !defined(__clang__) && \ + ((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || defined(CONFIG_UBSAN)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif uint64_t pool_guid = ((uint64_t *)attr.za_name)[0]; uint64_t os_guid = ((uint64_t *)attr.za_name)[1]; +#if defined(__GNUC__) && !defined(__clang__) && \ + ((!defined(_KERNEL) && defined(ZFS_UBSAN_ENABLED)) || \ + defined(CONFIG_UBSAN)) +#pragma GCC diagnostic pop +#endif error = zap_lookup_uint64(os, chain_map_zap, (uint64_t *)attr.za_name, 2, sizeof (uint64_t), sizeof (*szcmv) / sizeof (uint64_t),