<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Preprocessor output includes irrelevant line numbers from internal predefines buffer"
href="https://llvm.org/bugs/show_bug.cgi?id=28260">28260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Preprocessor output includes irrelevant line numbers from internal predefines buffer
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bruno-llvm@defraine.net
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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 (<a href="https://ccache.samba.org/">https://ccache.samba.org/</a>) 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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>