Skip to content

Commit

Permalink
Add test for certain gcc compilers with buggy cpp
Browse files Browse the repository at this point in the history
The preprocessor in later gcc versions is buggy,
returning extra lines and different "line numbers":

    # 1 "<built-in>"
    # 1 "<command-line>"
    # 31 "<command-line>"
    # 1 "/usr/include/stdc-predef.h" 1 3 4
    # 32 "<command-line>" 2

But it only does this when there are no macros,
otherwise (with -D) it returns the regular output:

    # 1 "<built-in>"
    # 1 "<command-line>"
    # 1 "/usr/include/stdc-predef.h" 1 3 4
    # 1 "<command-line>" 2
  • Loading branch information
afbjorklund committed Jul 14, 2016
1 parent 238430f commit cf8d693
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,38 @@ b"
b"
}

buggy_cpp_suite() {
testname="buggy_cpp"
$CCACHE -Cz >/dev/null
cat >buggy-cpp <<EOF
#!/bin/sh
CCACHE_DISABLE=1 # If $COMPILER happens to be a ccache symlink...
export CCACHE_DISABLE
if echo "\$*" | grep -- -D >/dev/null; then
$COMPILER "\$@"
else
# mistreat the preprocessor output in the same way as gcc6 does
$COMPILER "\$@" |
sed -e '/^# 1 "<command-line>"$/ a # 31 "<command-line>"' \\
-e 's/^# 1 "<command-line>" 2$/# 32 "<command-line>" 2/'
fi
exit 0
EOF
cat <<'EOF' >file.c
int foo;
EOF
chmod +x buggy-cpp
backdate buggy-cpp
$CCACHE ./buggy-cpp -c file.c
checkstat 'cache hit (direct)' 0
checkstat 'cache hit (preprocessed)' 0
checkstat 'cache miss' 1
$CCACHE ./buggy-cpp -DNOT_AFFECTING=1 -c file.c
checkstat 'cache hit (direct)' 0
checkstat 'cache hit (preprocessed)' 1
checkstat 'cache miss' 1
}

symlinks_suite() {
##################################################################
testname="symlink to source directory"
Expand Down Expand Up @@ -2577,6 +2609,7 @@ pch
symlinks
upgrade
prefix
buggy_cpp
"

case $host_os in
Expand Down

0 comments on commit cf8d693

Please sign in to comment.