llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.08k stars 11.59k forks source link

Erroneous clang -Warray-bounds warning when preprocessing its own output (Triggered by ccache) #26552

Closed llvmbot closed 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 26178
Resolution INVALID
Resolved on Jan 16, 2016 13:45
Version 3.7
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie

Extended Description

Hi all, please see:

When running the following command on the input (available using make bad SYSTEM_CLANG=/path/to/clang:

/usr/bin/clang -Warray-bounds -DFCS_COMPILE_DEBUG_FUNCTIONS=1 \ -DFCS_DBM_USE_LIBAVL=1 -DFCS_DBM_WITHOUT_CACHES=1 -DFCS_DEBONDT_DELTA_STATES=1 \ -O2 -g -DNDEBUG -fvisibility=hidden -march=corei7-avx -fomit-frame-pointer \ -E pi_make_microsoft_freecell_board.c -o pi_make_microsoft_freecell_board.i && \ /usr/bin/clang -DFCS_COMPILE_DEBUG_FUNCTIONS=1 -DFCS_DBM_USE_LIBAVL=1 \ -DFCS_DBM_WITHOUT_CACHES=1 -DFCS_DEBONDT_DELTA_STATES=1 -O2 -g -DNDEBUG \ -fvisibility=hidden -march=corei7-avx -fomit-frame-pointer -c \

I am getting a warning:

pi_make_microsoft_freecell_board.i pi_make_microsoft_freecell_board.c:168:2087: warning: array index 3 is past the end of the array (which contains 3 elements) [-Warray-bounds] ...result = (((const unsigned char ) (const char ) ("-t"))[3] - s2[3]... ^ ~ 1 warning generated. shlomif@telaviv1:~/Download/unpack/ccache-clang-stray-Warray-bounds-warning-bug$

I'm on Mageia Linux x86-64 v6 using clang from llvm-3.7.1-3.mga6.src.rpm .

Please look into it. Thank to Joel Rosdahl for some investigation and insights.

dwblaikie commented 8 years ago

I take it the bug you're reporting is that clang produces this warning when running over the preprocessed output, but does not produce the warning when running over the original code?

That is not itself a bug - Clang's diagnostic system detects the use of macros and uses them as hints to improve warning quality. Clang does not intend to produce the same output on preprocessed and non-preprocessed inputs.

For tools like ccache, you could consider using things like Clang's -frewrite-includes feature which handles the #includes but leaves macros in tact so that Clang's warning infrastructure can still see them. (include based warning behavior - such as suppressing certain warnings in system headers, may still work with -frewrite-includes output, I think (but don't quote me on that), since the file still has line directives to indicate which bits of code came from which header)