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