[RFC PATCH 10/12] pc-bios/optionrom: compile with -Wno-array-bounds

Paolo Bonzini posted 12 patches 3 years, 9 months ago
There is a newer version of this series
[RFC PATCH 10/12] pc-bios/optionrom: compile with -Wno-array-bounds
Posted by Paolo Bonzini 3 years, 9 months ago
Avoids the following bogus warning:

pvh_main.c: In function ‘pvh_load_kernel’:
pvh_main.c:101:42: warning: array subscript 0 is outside array bounds of ‘uint16_t[0]’ {aka ‘short unsigned int[]’} [-Warray-bounds]
  101 |         uint32_t ebda_paddr = ((uint32_t)*((uint16_t *)EBDA_BASE_ADDR)) << 4;
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 pc-bios/optionrom/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index 8de5a9461c..2494ad9c25 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -26,6 +26,7 @@ override CFLAGS += $(call cc-option, -fno-pie)
 override CFLAGS += -ffreestanding -I$(TOPSRC_DIR)/include
 override CFLAGS += $(call cc-option, -fno-stack-protector)
 override CFLAGS += $(call cc-option, -m16)
+override CFLAGS += $(call cc-option, -Wno-array-bounds)
 
 ifeq ($(filter -m16, $(CFLAGS)),)
 # Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
-- 
2.35.1



Re: [RFC PATCH 10/12] pc-bios/optionrom: compile with -Wno-array-bounds
Posted by Michael Tokarev 3 years, 9 months ago
29.04.2022 17:18, Paolo Bonzini wrote:
> Avoids the following bogus warning:
> 
> pvh_main.c: In function ‘pvh_load_kernel’:
> pvh_main.c:101:42: warning: array subscript 0 is outside array bounds of ‘uint16_t[0]’ {aka ‘short unsigned int[]’} [-Warray-bounds]
>    101 |         uint32_t ebda_paddr = ((uint32_t)*((uint16_t *)EBDA_BASE_ADDR)) << 4;
>        |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To me it looks like we should try to fix this particular expression
to make it more "compiler-friendly" than to disable warning for the
whole thing.

Which compiler (version) does this?

Thanks,

/mjt

Re: [RFC PATCH 10/12] pc-bios/optionrom: compile with -Wno-array-bounds
Posted by Paolo Bonzini 3 years, 9 months ago
On 5/2/22 09:37, Michael Tokarev wrote:
>>
>> pvh_main.c: In function ‘pvh_load_kernel’:
>> pvh_main.c:101:42: warning: array subscript 0 is outside array bounds 
>> of ‘uint16_t[0]’ {aka ‘short unsigned int[]’} [-Warray-bounds]
>>    101 |         uint32_t ebda_paddr = ((uint32_t)*((uint16_t 
>> *)EBDA_BASE_ADDR)) << 4;
>>        |                                          
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> To me it looks like we should try to fix this particular expression
> to make it more "compiler-friendly" than to disable warning for the
> whole thing.

I think this is really a compiler bug, or alternatively this case should 
be extracted to its own -W flag.

> Which compiler (version) does this?

The GCC 12.0.1 prerelease.

Paolo

Re: [RFC PATCH 10/12] pc-bios/optionrom: compile with -Wno-array-bounds
Posted by Richard Henderson 3 years, 9 months ago
On 4/29/22 07:18, Paolo Bonzini wrote:
> Avoids the following bogus warning:
> 
> pvh_main.c: In function ‘pvh_load_kernel’:
> pvh_main.c:101:42: warning: array subscript 0 is outside array bounds of ‘uint16_t[0]’ {aka ‘short unsigned int[]’} [-Warray-bounds]
>    101 |         uint32_t ebda_paddr = ((uint32_t)*((uint16_t *)EBDA_BASE_ADDR)) << 4;
>        |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~