Added some more information on how to use "delta" to reduce testcases.
[oota-llvm.git] / docs / HowToSubmitABug.html
1 <!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="#gccas">GCCAS bugs</a>
23     <li><a href="#gccld">GCCLD bugs</a>
24     <li><a href="#passes">Bugs in LLVM passes</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 <div class="doc_section">
42   <a name="introduction">Introduction - Got bugs?</a>
43 </div>
44 <!-- *********************************************************************** -->
45
46 <div class="doc_text">
47
48 <p>If you're working with LLVM and run into a bug, we definitely want to know
49 about it.  This document describes what you can do to increase the odds of
50 getting it fixed quickly.</p>
51
52 <p>Basically you have to do two things at a minimum.  First, decide whether the
53 bug <a href="#crashers">crashes the compiler</a> (or an LLVM pass), or if the
54 compiler is <a href="#miscompilations">miscompiling</a> the program.  Based on
55 what type of bug it is, follow the instructions in the linked section to narrow
56 down the bug so that the person who fixes it will be able to find the problem
57 more easily.</p>
58
59 <p>Once you have a reduced test-case, go to <a
60 href="http://llvm.org/bugs/enter_bug.cgi">the LLVM Bug Tracking
61 System</a>, select the category in which the bug falls, and fill out the form
62 with the necessary details.  The bug description should contain the following
63 information:</p>
64
65 <ul>
66   <li>All information necessary to reproduce the problem.</li>
67   <li>The reduced test-case that triggers the bug.</li>
68   <li>The location where you obtained LLVM (if not from our CVS
69   repository).</li>
70 </ul>
71
72 <p>Thanks for helping us make LLVM better!</p>
73
74 </div>
75
76 <!-- *********************************************************************** -->
77 <div class="doc_section">
78   <a name="crashers">Crashing Bugs</a>
79 </div>
80 <!-- *********************************************************************** -->
81
82 <div class="doc_text">
83
84 <p>More often than not, bugs in the compiler cause it to crash&mdash;often due to an
85 assertion failure of some sort.  If you are running <tt><b>opt</b></tt> 
86 directly, and something crashes, jump to the section on
87 <a href="#passes">bugs in LLVM passes</a>.  Otherwise, the most important
88 piece of the puzzle is to figure out if it is the GCC-based front-end that is
89 buggy or if it's one of the LLVM tools that has problems.</p>
90
91 <p>To figure out which program is crashing (the front-end,
92 <tt><b>gccas</b></tt>, or <tt><b>gccld</b></tt>), run the
93 <tt><b>llvm-gcc</b></tt> command line as you were when the crash occurred, but
94 add a <tt>-v</tt> option to the command line.  The compiler will print out a
95 bunch of stuff, and should end with telling you that one of
96 <tt><b>cc1</b>/<b>cc1plus</b></tt>, <tt><b>gccas</b></tt>, or
97 <tt><b>gccld</b></tt> crashed.</p>
98
99 <ul>
100
101   <li>If <tt><b>cc1</b></tt> or <tt><b>cc1plus</b></tt> crashed, you found a
102   problem with the front-end.
103   Jump ahead to the section on <a href="#front-end">front-end bugs</a>.</li>
104
105   <li>If <tt><b>gccas</b></tt> crashed, you found a bug in <a href="#gccas">one
106   of the passes in <tt><b>gccas</b></tt></a>.</li>
107
108   <li>If <tt><b>gccld</b></tt> crashed, you found a bug in <a href="#gccld">one
109   of the passes in <tt><b>gccld</b></tt></a>.</li>
110
111   <li>Otherwise, something really weird happened. Email the list with what you
112   have at this point.</li>
113
114 </ul>
115
116 </div>
117
118 <!-- ======================================================================= -->
119 <div class="doc_subsection">
120   <a name="front-end">Front-end bugs</a>
121 </div>
122
123 <div class="doc_text">
124
125 <p>If the problem is in the front-end, you should re-run the same
126 <tt>llvm-gcc</tt> command that resulted in the crash, but add the
127 <tt>-save-temps</tt> option.  The compiler will crash again, but it will leave
128 behind a <tt><i>foo</i>.i</tt> file (containing preprocessed C source code) and
129 possibly <tt><i>foo</i>.s</tt> (containing LLVM assembly code) for each
130 compiled <tt><i>foo</i>.c</tt> file. Send us the <tt><i>foo</i>.i</tt> file,
131 along with a brief description of the error it caused.</p>
132
133 <p>The <a href="http://delta.tigris.org/">delta</a> tool helps to reduce the
134 preprocessed file down to the smallest amount of code that still replicates the
135 problem. You're encouraged to use delta to reduce the code to make the
136 developers' lives easier. <a
137 href="http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction">This website</a>
138 has instructions on the best way to use delta.</p>
139
140 </div>
141
142 <!-- ======================================================================= -->
143 <div class="doc_subsection">
144   <a name="gccas">GCCAS bugs</a>
145 </div>
146
147 <div class="doc_text">
148
149 <p>If you find that a bug crashes in the <tt><b>gccas</b></tt> stage of
150 compilation, compile your test-case to a <tt>.s</tt> file with the
151 <tt>-save-temps</tt> option to <tt><b>llvm-gcc</b></tt>. Then run:</p>
152
153 <div class="doc_code">
154 <p><tt><b>gccas</b> -debug-pass=Arguments &lt; /dev/null -o - &gt; /dev/null</tt></p>
155 </div>
156
157 <p>... which will print a list of arguments, indicating the list of passes that
158 <tt><b>gccas</b></tt> runs.  Once you have the input file and the list of
159 passes, go to the section on <a href="#passes">debugging bugs in LLVM
160 passes</a>.</p>
161
162 </div>
163
164 <!-- ======================================================================= -->
165 <div class="doc_subsection">
166   <a name="gccld">GCCLD bugs</a>
167 </div>
168
169 <div class="doc_text">
170
171 <p>If you find that a bug crashes in the <tt><b>gccld</b></tt> stage of
172 compilation, gather all of the <tt>.o</tt> bytecode files and libraries that are
173 being linked together (the "<tt><b>llvm-gcc</b> -v</tt>" output should include
174 the full list of objects linked).  Then run:</p>
175
176 <div class="doc_code">
177 <p><tt><b>llvm-as</b> &lt; /dev/null &gt; null.bc<br>
178 <b>gccld</b> -debug-pass=Arguments null.bc</tt>
179 </p>
180 </div>
181
182 <p>... which will print a list of arguments, indicating the list of passes that
183 <tt><b>gccld</b></tt> runs.  Once you have the input files and the list of
184 passes, go to the section on <a href="#passes">debugging bugs in LLVM
185 passes</a>.</p>
186
187 </div>
188
189 <!-- ======================================================================= -->
190 <div class="doc_subsection">
191   <a name="passes">Bugs in LLVM passes</a>
192 </div>
193
194 <div class="doc_text">
195
196 <p>At this point, you should have some number of LLVM assembly files or bytecode
197 files and a list of passes which crash when run on the specified input.  In
198 order to reduce the list of passes (which is probably large) and the input to
199 something tractable, use the <tt><b>bugpoint</b></tt> tool as follows:</p>
200
201 <div class="doc_code">
202 <p><tt><b>bugpoint</b> &lt;input files&gt; &lt;list of passes&gt;</tt></p>
203 </div>
204
205 <p><tt><b>bugpoint</b></tt> will print a bunch of output as it reduces the
206 test-case, but it should eventually print something like this:</p>
207
208 <div class="doc_code">
209 <p><tt>
210 ...<br>
211 Emitted bytecode to 'bugpoint-reduced-simplified.bc'<br>
212 <br>
213 *** You can reproduce the problem with: opt bugpoint-reduced-simplified.bc -licm<br>
214 </tt></p>
215 </div>
216
217 <p>Once you complete this, please send the LLVM bytecode file and the command
218 line to reproduce the problem to the llvmbugs mailing list.</p>
219
220 </div>
221
222 <!-- *********************************************************************** -->
223 <div class="doc_section">
224   <a name="miscompilations">Miscompilations</a>
225 </div>
226 <!-- *********************************************************************** -->
227
228 <div class="doc_text">
229
230 <p>A miscompilation occurs when a pass does not correctly transform a program,
231 thus producing errors that are only noticed during execution. This is different
232 from producing invalid LLVM code (i.e., code not in SSA form, using values
233 before defining them, etc.) which the verifier will check for after a pass
234 finishes its run.</p>
235
236 <p>If it looks like the LLVM compiler is miscompiling a program, the very first
237 thing to check is to make sure it is not using undefined behavior.  In
238 particular, check to see if the program <a
239 href="http://valgrind.kde.org/">valgrind</a>s clean, passes purify, or some
240 other memory checker tool.  Many of the "LLVM bugs" that we have chased down
241 ended up being bugs in the program being compiled, not LLVM.</p>
242
243 <p>Once you determine that the program itself is not buggy, you should choose 
244 which code generator you wish to compile the program with (e.g. C backend, the 
245 JIT, or LLC) and optionally a series of LLVM passes to run.  For example:</p>
246
247 <div class="doc_code">
248 <p><tt>
249 <b>bugpoint</b> -run-cbe [... optzn passes ...] file-to-test.bc --args -- [program arguments]</tt></p>
250 </div>
251
252 <p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass
253 that causes an error, and simplify the bytecode file as much as it can to assist
254 you. It will print a message letting you know how to reproduce the resulting
255 error.</p>
256
257 </div>
258
259 <!-- *********************************************************************** -->
260 <div class="doc_section">
261   <a name="codegen">Incorrect code generation</a>
262 </div>
263 <!-- *********************************************************************** -->
264
265 <div class="doc_text">
266
267 <p>Similarly to debugging incorrect compilation by mis-behaving passes, you can
268 debug incorrect code generation by either LLC or the JIT, using
269 <tt>bugpoint</tt>. The process <tt>bugpoint</tt> follows in this case is to try
270 to narrow the code down to a function that is miscompiled by one or the other
271 method, but since for correctness, the entire program must be run,
272 <tt>bugpoint</tt> will compile the code it deems to not be affected with the C
273 Backend, and then link in the shared object it generates.</p>
274
275 <p>To debug the JIT:</p>
276
277 <div class="doc_code">
278 <pre>
279 bugpoint -run-jit -output=[correct output file] [bytecode file]  \
280          --tool-args -- [arguments to pass to lli]               \
281          --args -- [program arguments]
282 </pre>
283 </div>
284
285 <p>Similarly, to debug the LLC, one would run:</p>
286
287 <div class="doc_code">
288 <pre>
289 bugpoint -run-llc -output=[correct output file] [bytecode file]  \
290          --tool-args -- [arguments to pass to llc]               \
291          --args -- [program arguments]
292 </pre>
293 </div>
294
295 <p><b>Special note:</b> if you are debugging MultiSource or SPEC tests that
296 already exist in the <tt>llvm/test</tt> hierarchy, there is an easier way to
297 debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which
298 will pass the program options specified in the Makefiles:</p>
299
300 <div class="doc_code">
301 <p><tt>
302 cd llvm/test/../../program<br>
303 make bugpoint-jit
304 </tt></p>
305 </div>
306
307 <p>At the end of a successful <tt>bugpoint</tt> run, you will be presented
308 with two bytecode files: a <em>safe</em> file which can be compiled with the C
309 backend and the <em>test</em> file which either LLC or the JIT
310 mis-codegenerates, and thus causes the error.</p>
311
312 <p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do
313 the following:</p>
314
315 <ol>
316
317 <li><p>Regenerate the shared object from the safe bytecode file:</p>
318
319 <div class="doc_code">
320 <p><tt>
321 <b>llc</b> -march=c safe.bc -o safe.c<br>
322 <b>gcc</b> -shared safe.c -o safe.so
323 </tt></p>
324 </div></li>
325
326 <li><p>If debugging LLC, compile test bytecode native and link with the shared
327     object:</p>
328
329 <div class="doc_code">
330 <p><tt>
331 <b>llc</b> test.bc -o test.s -f<br>
332 <b>gcc</b> test.s safe.so -o test.llc<br>
333 ./test.llc [program options]
334 </tt></p>
335 </div></li>
336     
337 <li><p>If debugging the JIT, load the shared object and supply the test
338     bytecode:</p>
339
340 <div class="doc_code">
341 <p><tt><b>lli</b> -load=safe.so test.bc [program options]</tt></p>
342 </div></li>  
343
344 </ol>
345
346 </div>
347
348 <!-- *********************************************************************** -->
349 <hr>
350 <address>
351   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
352   src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
353   <a href="http://validator.w3.org/check/referer"><img
354   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
355
356   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
357   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a>
358   <br>
359   Last modified: $Date$
360 </address>
361
362 </body>
363 </html>