[Bug tree-optimization/85175] [8 regression] false-positive -Wformat-overflow= warning with gcc-8 -Os
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Apr 4 14:32:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85175
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
I wonder if adding an attribute to constrain the range of a variable on
declaration would be a solution. That way the first warning on your list, for
example, could be avoided by annotating id along the lines of:
struct acpi_processor {
acpi_handle handle;
u32 acpi_id;
phys_cpuid_t phys_id; /* CPU hardware ID such as APIC ID for x86 */
u32 id __attribute__ ((range (0, CONFIG_NR_CPUS))); /* CPU logical
ID allocated by OS */
...
};
and have GCC use that range on each read access to id. This could also improve
code generation. (Things would of course break badly if id were assigned an
out-of-bounds value; GCC could help by warning on such assignments if/when it
caught them.)
This might be something to consider for GCC 9 (it's too late for GCC 8).
More information about the Gcc-bugs
mailing list