• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                      "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6  <title>How to submit an LLVM bug report</title>
7  <link rel="stylesheet" href="llvm.css" type="text/css">
8</head>
9<body>
10
11<h1>
12  How to submit an LLVM bug report
13</h1>
14
15<table class="layout" style="width: 90%" >
16<tr class="layout">
17  <td class="left">
18<ol>
19  <li><a href="#introduction">Introduction - Got bugs?</a></li>
20  <li><a href="#crashers">Crashing Bugs</a>
21    <ul>
22    <li><a href="#front-end">Front-end bugs</a>
23    <li><a href="#ct_optimizer">Compile-time optimization bugs</a>
24    <li><a href="#ct_codegen">Code generator bugs</a>
25    </ul></li>
26  <li><a href="#miscompilations">Miscompilations</a></li>
27  <li><a href="#codegen">Incorrect code generation (JIT and LLC)</a></li>
28</ol>
29<div class="doc_author">
30  <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> and
31                <a href="http://misha.brukman.net">Misha Brukman</a></p>
32</div>
33</td>
34<td class="right">
35  <img src="img/Debugging.gif" alt="Debugging" width="444" height="314">
36</td>
37</tr>
38</table>
39
40<!-- *********************************************************************** -->
41<h2>
42  <a name="introduction">Introduction - Got bugs?</a>
43</h2>
44<!-- *********************************************************************** -->
45
46<div>
47
48<p>If you're working with LLVM and run into a bug, we definitely want to know
49about it.  This document describes what you can do to increase the odds of
50getting it fixed quickly.</p>
51
52<p>Basically you have to do two things at a minimum.  First, decide whether the
53bug <a href="#crashers">crashes the compiler</a> (or an LLVM pass), or if the
54compiler is <a href="#miscompilations">miscompiling</a> the program (i.e., the
55compiler successfully produces an executable, but it doesn't run right).  Based
56on
57what type of bug it is, follow the instructions in the linked section to narrow
58down the bug so that the person who fixes it will be able to find the problem
59more easily.</p>
60
61<p>Once you have a reduced test-case, go to <a
62href="http://llvm.org/bugs/enter_bug.cgi">the LLVM Bug Tracking
63System</a> and fill out the form with the necessary details (note that you don't
64need to pick a category, just use the "new-bugs" category if you're not sure).
65The bug description should contain the following
66information:</p>
67
68<ul>
69  <li>All information necessary to reproduce the problem.</li>
70  <li>The reduced test-case that triggers the bug.</li>
71  <li>The location where you obtained LLVM (if not from our Subversion
72  repository).</li>
73</ul>
74
75<p>Thanks for helping us make LLVM better!</p>
76
77</div>
78
79<!-- *********************************************************************** -->
80<h2>
81  <a name="crashers">Crashing Bugs</a>
82</h2>
83<!-- *********************************************************************** -->
84
85<div>
86
87<p>More often than not, bugs in the compiler cause it to crash&mdash;often due
88to an assertion failure of some sort. The most important
89piece of the puzzle is to figure out if it is crashing in the GCC front-end
90or if it is one of the LLVM libraries (e.g. the optimizer or code generator)
91that has problems.</p>
92
93<p>To figure out which component is crashing (the front-end,
94optimizer or code generator), run the
95<tt><b>llvm-gcc</b></tt> command line as you were when the crash occurred, but
96with the following extra command line options:</p>
97
98<ul>
99  <li><tt><b>-O0 -emit-llvm</b></tt>: If <tt>llvm-gcc</tt> still crashes when
100  passed these options (which disable the optimizer and code generator), then
101  the crash is in the front-end.  Jump ahead to the section on <a
102  href="#front-end">front-end bugs</a>.</li>
103
104  <li><tt><b>-emit-llvm</b></tt>: If <tt>llvm-gcc</tt> crashes with this option
105  (which disables the code generator), you found an optimizer bug.  Jump ahead
106  to <a href="#ct_optimizer"> compile-time optimization bugs</a>.</li>
107
108  <li>Otherwise, you have a code generator crash.  Jump ahead to <a
109  href="#ct_codegen">code generator bugs</a>.</li>
110
111</ul>
112
113<!-- ======================================================================= -->
114<h3>
115  <a name="front-end">Front-end bugs</a>
116</h3>
117
118<div>
119
120<p>If the problem is in the front-end, you should re-run the same
121<tt>llvm-gcc</tt> command that resulted in the crash, but add the
122<tt>-save-temps</tt> option.  The compiler will crash again, but it will leave
123behind a <tt><i>foo</i>.i</tt> file (containing preprocessed C source code) and
124possibly <tt><i>foo</i>.s</tt> for each
125compiled <tt><i>foo</i>.c</tt> file. Send us the <tt><i>foo</i>.i</tt> file,
126along with the options you passed to llvm-gcc, and a brief description of the
127error it caused.</p>
128
129<p>The <a href="http://delta.tigris.org/">delta</a> tool helps to reduce the
130preprocessed file down to the smallest amount of code that still replicates the
131problem. You're encouraged to use delta to reduce the code to make the
132developers' lives easier. <a
133href="http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction">This website</a>
134has instructions on the best way to use delta.</p>
135
136</div>
137
138<!-- ======================================================================= -->
139<h3>
140  <a name="ct_optimizer">Compile-time optimization bugs</a>
141</h3>
142
143<div>
144
145<p>If you find that a bug crashes in the optimizer, compile your test-case to a
146<tt>.bc</tt> file by passing "<tt><b>-emit-llvm -O0 -c -o foo.bc</b></tt>".
147Then run:</p>
148
149<div class="doc_code">
150<p><tt><b>opt</b> -std-compile-opts -debug-pass=Arguments foo.bc
151    -disable-output</tt></p>
152</div>
153
154<p>This command should do two things: it should print out a list of passes, and
155then it should crash in the same way as llvm-gcc.  If it doesn't crash, please
156follow the instructions for a <a href="#front-end">front-end bug</a>.</p>
157
158<p>If this does crash, then you should be able to debug this with the following
159bugpoint command:</p>
160
161<div class="doc_code">
162<p><tt><b>bugpoint</b> foo.bc &lt;list of passes printed by
163<b>opt</b>&gt;</tt></p>
164</div>
165
166<p>Please run this, then file a bug with the instructions and reduced .bc files
167that bugpoint emits.  If something goes wrong with bugpoint, please submit the
168"foo.bc" file and the list of passes printed by <b>opt</b>.</p>
169
170</div>
171
172<!-- ======================================================================= -->
173<h3>
174  <a name="ct_codegen">Code generator bugs</a>
175</h3>
176
177<div>
178
179<p>If you find a bug that crashes llvm-gcc in the code generator, compile your
180source file to a .bc file by passing "<tt><b>-emit-llvm -c -o foo.bc</b></tt>"
181to llvm-gcc (in addition to the options you already pass).  Once your have
182foo.bc, one of the following commands should fail:</p>
183
184<ol>
185<li><tt><b>llc</b> foo.bc</tt></li>
186<li><tt><b>llc</b> foo.bc -relocation-model=pic</tt></li>
187<li><tt><b>llc</b> foo.bc -relocation-model=static</tt></li>
188</ol>
189
190<p>If none of these crash, please follow the instructions for a
191<a href="#front-end">front-end bug</a>.  If one of these do crash, you should
192be able to reduce this with one of the following bugpoint command lines (use
193the one corresponding to the command above that failed):</p>
194
195<ol>
196<li><tt><b>bugpoint</b> -run-llc foo.bc</tt></li>
197<li><tt><b>bugpoint</b> -run-llc foo.bc --tool-args
198           -relocation-model=pic</tt></li>
199<li><tt><b>bugpoint</b> -run-llc foo.bc --tool-args
200           -relocation-model=static</tt></li>
201</ol>
202
203<p>Please run this, then file a bug with the instructions and reduced .bc file
204that bugpoint emits.  If something goes wrong with bugpoint, please submit the
205"foo.bc" file and the option that llc crashes with.</p>
206
207</div>
208
209</div>
210
211<!-- *********************************************************************** -->
212<h2>
213  <a name="miscompilations">Miscompilations</a>
214</h2>
215<!-- *********************************************************************** -->
216
217<div>
218
219<p>If llvm-gcc successfully produces an executable, but that executable doesn't
220run right, this is either a bug in the code or a bug in the
221compiler.  The first thing to check is to make sure it is not using undefined
222behavior (e.g. reading a variable before it is defined).  In particular, check
223to see if the program <a href="http://valgrind.org/">valgrind</a>s clean,
224passes purify, or some other memory checker tool.  Many of the "LLVM bugs" that
225we have chased down ended up being bugs in the program being compiled, not
226 LLVM.</p>
227
228<p>Once you determine that the program itself is not buggy, you should choose
229which code generator you wish to compile the program with (e.g. C backend, the
230JIT, or LLC) and optionally a series of LLVM passes to run.  For example:</p>
231
232<div class="doc_code">
233<p><tt>
234<b>bugpoint</b> -run-cbe [... optzn passes ...] file-to-test.bc --args -- [program arguments]</tt></p>
235</div>
236
237<p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass
238that causes an error, and simplify the bitcode file as much as it can to assist
239you. It will print a message letting you know how to reproduce the resulting
240error.</p>
241
242</div>
243
244<!-- *********************************************************************** -->
245<h2>
246  <a name="codegen">Incorrect code generation</a>
247</h2>
248<!-- *********************************************************************** -->
249
250<div>
251
252<p>Similarly to debugging incorrect compilation by mis-behaving passes, you can
253debug incorrect code generation by either LLC or the JIT, using
254<tt>bugpoint</tt>. The process <tt>bugpoint</tt> follows in this case is to try
255to narrow the code down to a function that is miscompiled by one or the other
256method, but since for correctness, the entire program must be run,
257<tt>bugpoint</tt> will compile the code it deems to not be affected with the C
258Backend, and then link in the shared object it generates.</p>
259
260<p>To debug the JIT:</p>
261
262<div class="doc_code">
263<pre>
264bugpoint -run-jit -output=[correct output file] [bitcode file]  \
265         --tool-args -- [arguments to pass to lli]              \
266         --args -- [program arguments]
267</pre>
268</div>
269
270<p>Similarly, to debug the LLC, one would run:</p>
271
272<div class="doc_code">
273<pre>
274bugpoint -run-llc -output=[correct output file] [bitcode file]  \
275         --tool-args -- [arguments to pass to llc]              \
276         --args -- [program arguments]
277</pre>
278</div>
279
280<p><b>Special note:</b> if you are debugging MultiSource or SPEC tests that
281already exist in the <tt>llvm/test</tt> hierarchy, there is an easier way to
282debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which
283will pass the program options specified in the Makefiles:</p>
284
285<div class="doc_code">
286<p><tt>
287cd llvm/test/../../program<br>
288make bugpoint-jit
289</tt></p>
290</div>
291
292<p>At the end of a successful <tt>bugpoint</tt> run, you will be presented
293with two bitcode files: a <em>safe</em> file which can be compiled with the C
294backend and the <em>test</em> file which either LLC or the JIT
295mis-codegenerates, and thus causes the error.</p>
296
297<p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do
298the following:</p>
299
300<ol>
301
302<li><p>Regenerate the shared object from the safe bitcode file:</p>
303
304<div class="doc_code">
305<p><tt>
306<b>llc</b> -march=c safe.bc -o safe.c<br>
307<b>gcc</b> -shared safe.c -o safe.so
308</tt></p>
309</div></li>
310
311<li><p>If debugging LLC, compile test bitcode native and link with the shared
312    object:</p>
313
314<div class="doc_code">
315<p><tt>
316<b>llc</b> test.bc -o test.s<br>
317<b>gcc</b> test.s safe.so -o test.llc<br>
318./test.llc [program options]
319</tt></p>
320</div></li>
321
322<li><p>If debugging the JIT, load the shared object and supply the test
323    bitcode:</p>
324
325<div class="doc_code">
326<p><tt><b>lli</b> -load=safe.so test.bc [program options]</tt></p>
327</div></li>
328
329</ol>
330
331</div>
332
333<!-- *********************************************************************** -->
334<hr>
335<address>
336  <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
337  src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
338  <a href="http://validator.w3.org/check/referer"><img
339  src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
340
341  <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
342  <a href="http://llvm.org/">The LLVM Compiler Infrastructure</a>
343  <br>
344  Last modified: $Date$
345</address>
346
347</body>
348</html>
349