[llvm-bugs] [Bug 28260] New: Preprocessor output includes irrelevant line numbers from internal predefines buffer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 22 02:47:37 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28260

            Bug ID: 28260
           Summary: Preprocessor output includes irrelevant line numbers
                    from internal predefines buffer
           Product: clang
           Version: 3.8
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bruno-llvm at defraine.net
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider the following example using clang 3.8.0:

$ touch a.h
$ touch b.c
$ clang -E -include a.h b.c
# 1 "b.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 317 "<built-in>" 3
# 1 "<command line>" 1
# 1 "./a.h" 1
# 2 "<command line>" 2
# 1 "<built-in>" 2
# 1 "b.c" 2

The line numbers 317 <built-in> and 2 <command line> refer to the Predefines
buffer that the clang preprocessor has constructed and do not concern me.

The line number also appear in error messages:

$ echo "some thing" > b.h
$ clang -c -include a.h -include b.h b.c
In file included from <built-in>:317:
In file included from <command line>:2:
./b.h:1:1: error: unknown type name 'some'
some thing
^
./b.h:1:11: error: expected ';' after top level declarator
some thing
          ^
          ;
2 errors generated.

The concrete practical problem is that the preprocessor output will change when
adding/removing command-line (un)defines, and this will trigger tools like
ccache (https://ccache.samba.org/) to always rerun the compiler, even when the
(un)defines do not affect the program:

$ clang -E -include a.h -DFOO -DBAR b.c
# 1 "b.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 317 "<built-in>" 3
# 1 "<command line>" 1


# 1 "./a.h" 1
# 4 "<command line>" 2
# 1 "<built-in>" 2
# 1 "b.c" 2

Note the added empty lines (to adjust line numbers) and the changed line info
on "<command line>". These changes trigger the recompilation by ccache.

GCC has stable preprocessor output:

$ gcc -E -include a.h b.c
# 1 "b.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "./a.h" 1
# 1 "<command-line>" 2
# 1 "b.c"

$ gcc -E -include a.h -DFOO -DBAR b.c
# 1 "b.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "./a.h" 1
# 1 "<command-line>" 2
# 1 "b.c"

$ gcc -c -include a.h -include b.h b.c
In file included from <command-line>:1:0:
./b.h:1:1: error: unknown type name ‘some’
 some thing
 ^
b.c:1:0: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of
input

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160622/4b6c8a89/attachment.html>


More information about the llvm-bugs mailing list