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