Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Closed Quuxplusone closed 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR26178
Status RESOLVED INVALID
Importance P normal
Reported by Shlomi Fish (shlomif@shlomifish.org)
Reported on 2016-01-16 13:40:02 -0800
Last modified on 2016-01-16 13:45:39 -0800
Version 3.7
Hardware PC Linux
CC dblaikie@gmail.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Hi all, please see:

* https://github.com/shlomif/ccache-clang-stray-Warray-bounds-warning-bug

* https://bugzilla.samba.org/show_bug.cgi?id=11674

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.
Quuxplusone 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)