[RFC] how to handle the combination of -fstrict-flex-arrays + -Warray-bounds
Qing Zhao
qing.zhao@oracle.com
Fri Oct 21 15:29:28 GMT 2022
Hi,
(FAM below refers to Flexible Array Members):
I need inputs on how to handle the combination of -fstrict-flex-arrays + -Warray-bounds.
Our initial goal is to update -Warray-bounds with multiple levels of -fstrict-flex-arrays=N
to issue warnings according to the different levels of “N”.
However, after detailed study, I found that this goal was very hard to be achieved.
1. -fstrict-flex-arrays and its levels
The new option -fstrict-flex-arrays has 4 levels:
level trailing arrays
treated as FAM
0 [],[0],[1],[n] the default without option
1 [],[0],[1]
2 [],[0]
3 [] the default when option specified without value
2. -Warray-bounds and its levels
The option -Warray-bounds currently has 2 levels:
level trailing arrays
treated as FAM
1 [],[0],[1] the default when option specified without value
2 []
i.e,
When -Warray-bounds=1, it treats [],[0],[1] as FAM, the same level as -fstrict-flex-arrays=1;
When -Warray-bounds=2, it only treat [] as FAM, the same level as -fstrict-flex-arrays=3;
3. How to handle the combination of -fstrict-flex-arrays and -Warray-bounds?
Question 1: when -fstrict-flex-arrays does not present, the default is -strict-flex-arrays=0,
which treats [],[0],[1],[n] as FAM, so should we update the default behavior
of -Warray-bounds to treat any trailing array [n] as FAMs?
My immediate answer to Q1 is NO, we shouldn’t, that will be a big regression on -Warray-bounds, right?
Question 2: when -fstrict-flex-arrays=N1 and -Warray-bounds=N2 present at the same time,
Which one has higher priority? N1 or N2?
-fstrict-flex-arrays=N1 controls how the compiler code generation treats the trailing arrays as FAMs, it seems
reasonable to give higher priority to N1, However, then should we completely disable the level of -Warray-bounds
N2 under such situation?
I really don’t know what’s the best way to handle the conflict between N1 and N2.
Can we completely cancel the 2 levels of -Warray-bounds, and always honor the level of -fstrict-flex-arrays?
Any comments or suggestion will be helpful.
thanks.
Qing
More information about the Gcc-patches
mailing list