]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add test for certain gcc compilers with buggy cpp
authorAnders Björklund <anders@itension.se>
Thu, 14 Jul 2016 15:28:20 +0000 (17:28 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 19 Jul 2016 14:59:39 +0000 (16:59 +0200)
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

test.sh

diff --git a/test.sh b/test.sh
index 2f3a45af2e459b96e779bf4102ebdaca95b00ac0..30aa3eb71dfe410144117cb1138200a91009bd31 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -2432,6 +2432,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"
@@ -2598,6 +2630,7 @@ pch
 symlinks
 upgrade
 prefix
+buggy_cpp
 "
 
 case $host_os in