https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121036
Bug ID: 121036
Summary: bogus -Warray-bounds with cse-able conditions
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: amylaar at gcc dot gnu.org
Blocks: 56456
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Created attachment 61840
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61840&action=edit
reduced test case, compile with -c -Werror -Wall -O2
$ ./xgcc -B./ ../et181.c -c -Werror -Wall -O2
../et181.c: In function ‘virt_to_phys’:
../et181.c:79:84: error: array subscript 4 is above array bounds of ‘const char
* const[4]’ [-Werror=array-bounds=]
79 | printf("%s mode %s\n", cpu->tc_p ? "User" : "Supervisor",
access_type[access]);
|
~~~~~~~~~~~^~~~~~~~
../et181.c:43:22: note: while referencing ‘access_type’
43 | const char * const access_type[] = {"write", "read", "execute",
"disassembler"};
| ^~~~~~~~~~~
cc1: all warnings being treated as errors
There is no reason to assume the function would be called with an invalid enum
value.
I suppose that is an artefact from code duplication and/or jump threading.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds