[cfe-dev] -Warray-bounds seems over-zealous on Clang

Andrew Fish afish at apple.com
Tue Jul 12 09:52:36 PDT 2011

On Jul 12, 2011, at 8:54 AM, Peter Geoghegan wrote:

> Saying "just use C99" isn't a practical solution. This is a mature
> project with a large codebase, that targets many compilers, including,
> for a large number of reasons, Visual Studio - Microsoft have
> absolutely no interest in pursuing C99 support.

We have had the same problem in the EFI firmware open source project (edk2). The edk2 project supports Visual Studio 20XX, gcc, RVCT, clang, ...

> Besides, the chances of Clang actually helpfully diagnosing a problem
> with the delta between how GCC does -Warray-bounds and how Clang does
> it are slim - how often are these problems statically detectable? This
> is C.

We have found real bugs in chipset and driver code with clangs -Warray-bounds, that the other compilers did not find. 

So, given it is C, we just add a int *value = &A.value[0], and replace A.value[n] with value[n]. 

Luckily for us the case of the value[1] variable length array were mostly in regards to processing data structures from specifications and we had a single C function per instance that was doing the parsing. The changes were accepted to the open source project, so we did not have to turn off -Warray-bounds.

> Even if your position wasn't unreasonable, which it is, Clang still
> gives this warning when the -c89 flag is given.
> -- 
> Peter Geoghegan       http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training and Services
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list