]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Work around preprocessor bugs in gcc version 6
authorAnders Björklund <anders@itension.se>
Sun, 26 Jun 2016 21:03:59 +0000 (23:03 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 11 Jul 2016 19:24:55 +0000 (21:24 +0200)
Before hashing the output of the preprocessor (gcc -E):
- Ignore extra line `# 31 "<command-line>"` completely.
- Replace `# 32 "<command-line>" 2` with the regular # 1.
For some reason this only happens with gcc without macros.

Closes #96

ccache.c

index b61fac4cbe89f1d94f7851b1fce9af806f1d0aea..1197e618e55c35fda8a67c14bf35c8c512a3ed5b 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -750,6 +750,28 @@ process_preprocessed_file(struct mdfour *hash, const char *path)
                    && (q == data || q[-1] == '\n')) {
                        char *path;
 
+                       /* Workarounds for preprocessor linemarker bugs in GCC version 6 */
+                       if (q[2] == '3') {
+                               if (str_startswith(q, "# 31 \"<command-line>\"\n")) {
+                                       /* Bogus extra line with #31, after the regular #1:
+                                          Ignore the whole line, and continue parsing */
+                                       while (q < end && *q != '\n') {
+                                               q++;
+                                       }
+                                       p = q;
+                                       continue;
+                               } else if (str_startswith(q, "# 32 \"<command-line>\" 2\n")) {
+                                       /* Bogus wrong line with #32, instead of regular #1:
+                                          Replace the line number with the usual one */
+                                       hash_buffer(hash, p, q - p);
+                                       q += 1;
+                                       q[0] = '#';
+                                       q[1] = ' ';
+                                       q[2] = '1';
+                                       p = q;
+                               }
+                       }
+
                        while (q < end && *q != '"' && *q != '\n') {
                                q++;
                        }