Fixed a comma error.
[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 <div>
15
16 <table border="0" width="100%">
17 <tr>
18 <td valign="top">
19
20 <ol>
21   <li><a href="#introduction">Introduction - Got bugs?</a></li>
22   <li><a href="#crashers">Crashing Bugs</a>
23     <ul>
24     <li><a href="#front-end">Front-end bugs</a>
25     <li><a href="#gccas">GCCAS bugs</a>
26     <li><a href="#gccld">GCCLD bugs</a>
27     <li><a href="#passes">Bugs in LLVM passes</a>
28     </ul></li>
29   <li><a href="#miscompilations">Miscompilations</a></li>
30   <li><a href="#codegen">Incorrect code generation (JIT and LLC)</a></li>
31
32 </ol>
33
34 <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> and
35                  <a href="http://misha.brukman.net">Misha Brukman</a></b></p>
36
37 </td>
38 <td align="right">
39   <img src="Debugging.gif" 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 <tt><b>cc1</b></tt>,
100 <tt><b>gccas</b></tt>, or <tt><b>gccld</b></tt> crashed.</p>
101
102 <ul>
103
104   <li>If <tt><b>cc1</b></tt> crashed, you found a problem with the front-end.
105   Jump ahead to the section on <a href="#front-end">front-end bugs</a>.</li>
106
107   <li>If <tt><b>gccas</b></tt> crashed, you found a bug in <a href="#gccas">one
108   of the passes in <tt><b>gccas</b></tt></a>.</li>
109
110   <li>If <tt><b>gccld</b></tt> crashed, you found a bug in <a href="#gccld">one
111   of the passes in <tt><b>gccld</b></tt></a>.</li>
112
113   <li>Otherwise, something really weird happened. Email the list with what you
114   have at this point.</li>
115
116 </ul>
117
118 </div>
119
120 <!-- ======================================================================= -->
121 <div class="doc_subsection">
122   <a name="front-end">Front-end bugs</a>
123 </div>
124
125 <div class="doc_text">
126
127 <p>If the problem is in the front-end, you should re-run the same
128 <tt>llvm-gcc</tt> command that resulted in the crash, but add the
129 <tt>-save-temps</tt> option.  The compiler will crash again, but it will leave
130 behind a <tt><i>foo</i>.i</tt> file (containing preprocessed C source code) and
131 possibly <tt><i>foo</i>.s</tt> (containing LLVM assembly code), for each
132 compiled <tt><i>foo</i>.c</tt> file. Send us the <tt><i>foo</i>.i</tt> file,
133 along with a brief description of the error it caused.</p>
134
135 </div>
136
137 <!-- ======================================================================= -->
138 <div class="doc_subsection">
139   <a name="gccas">GCCAS bugs</a>
140 </div>
141
142 <div class="doc_text">
143
144 <p>If you find that a bug crashes in the <tt><b>gccas</b></tt> stage of
145 compilation, compile your test-case to a <tt>.s</tt> file with the
146 <tt>-save-temps</tt> option to <tt><b>llvm-gcc</b></tt>. Then run:</p>
147
148 <pre>
149   <b>gccas</b> -debug-pass=Arguments &lt; /dev/null -o - &gt; /dev/null
150 </pre>
151
152 <p>... which will print a list of arguments, indicating the list of passes that
153 <tt><b>gccas</b></tt> runs.  Once you have the input file and the list of
154 passes, go to the section on <a href="#passes">debugging bugs in LLVM
155 passes</a>.</p>
156
157 </div>
158
159 <!-- ======================================================================= -->
160 <div class="doc_subsection">
161   <a name="gccld">GCCLD bugs</a>
162 </div>
163
164 <div class="doc_text">
165
166 <p>If you find that a bug crashes in the <tt><b>gccld</b></tt> stage of
167 compilation, gather all of the <tt>.o</tt> bytecode files and libraries that are
168 being linked together (the "<tt><b>llvm-gcc</b> -v</tt>" output should include
169 the full list of objects linked).  Then run:</p>
170
171 <pre>
172   <b>llvm-as</b> &lt; /dev/null &gt; null.bc
173   <b>gccld</b> -debug-pass=Arguments null.bc
174 </pre><p>
175
176 <p>... which will print a list of arguments, indicating the list of passes that
177 <tt><b>gccld</b></tt> runs.  Once you have the input files and the list of
178 passes, go to the section on <a href="#passes">debugging bugs in LLVM
179 passes</a>.</p>
180
181 </div>
182
183 <!-- ======================================================================= -->
184 <div class="doc_subsection">
185   <a name="passes">Bugs in LLVM passes</a>
186 </div>
187
188 <div class="doc_text">
189
190 <p>At this point, you should have some number of LLVM assembly files or bytecode
191 files and a list of passes which crash when run on the specified input.  In
192 order to reduce the list of passes (which is probably large) and the input to
193 something tractable, use the <tt><b>bugpoint</b></tt> tool as follows:</p>
194
195 <pre>
196   <b>bugpoint</b> &lt;input files&gt; &lt;list of passes&gt;
197 </pre><p>
198
199 <p><tt><b>bugpoint</b></tt> will print a bunch of output as it reduces the
200 test-case, but it should eventually print something like this:</p>
201
202 <pre>
203   ...
204   Emitted bytecode to 'bugpoint-reduced-simplified.bc'
205
206   *** You can reproduce the problem with: opt bugpoint-reduced-simplified.bc -licm
207 </pre>
208
209 <p>Once you complete this, please send the LLVM bytecode file and the command
210 line to reproduce the problem to the llvmbugs mailing list.</p>
211
212 </div>
213
214 <!-- *********************************************************************** -->
215 <div class="doc_section">
216   <a name="miscompilations">Miscompilations</a>
217 </div>
218 <!-- *********************************************************************** -->
219
220 <div class="doc_text">
221
222 <p>A miscompilation occurs when a pass does not correctly transform a program,
223 thus producing errors that are only noticed during execution. This is different
224 from producing invalid LLVM code (i.e., code not in SSA form, using values
225 before defining them, etc.) which the verifier will check for after a pass
226 finishes its run.</p>
227
228 <p>To debug a miscompilation, you should choose which program you wish to run
229 the output through, e.g. C backend, the JIT, or LLC, and a selection of passes,
230 one of which may be causing the error, and run, for example:</p>
231
232 <pre>
233   <b>bugpoint</b> -run-cbe [... optimization passes ...] file-to-test.bc
234 </pre>
235
236 <p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass
237 that causes an error, and simplify the bytecode file as much as it can to assist
238 you. It will print a message letting you know how to reproduce the resulting
239 error.</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
252 debug 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
254 to narrow the code down to a function that is miscompiled by one or the other
255 method, 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
257 Backend, and then link in the shared object it generates.</p>
258
259 <p>To debug the JIT:</p>
260
261 <pre>
262   <b>bugpoint</b> -run-jit -output=[correct output file] [bytecodefile]
263 </pre>
264
265 <p>Similarly, to debug the LLC, one would run:</p>
266
267 <pre>
268   <b>bugpoint</b> -run-llc -output=[correct output file] [bytecodefile]
269 </pre>
270
271 <p>At the end of a successful <tt>bugpoint</tt> run, you will be presented
272 with two bytecode files: a <em>safe</em> file which can be compiled with the C
273 backend and the <em>test</em> file which either LLC or the JIT
274 mis-codegenerates, and thus causes the error.</p>
275
276 <p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do
277 the following:</p>
278
279 <ol>
280
281   <li>Regenerate the shared object from the safe bytecode file:<br>
282
283 <pre>
284   <b>llvm-dis</b> -c safe.bc -o safe.c<br>
285   <b>gcc</b> -shared safe.c -o safe.so
286 </pre></li>
287
288   <li>If debugging LLC, compile test bytecode native and link with the shared object:<br>
289
290 <pre>
291   <b>llc</b> test.bc -o test.s -f<br>
292   gcc test.s safe.so -o test.llc<br>
293   ./test.llc [program options]
294 </pre></li>
295       
296 <p>If debugging the JIT, load the shared object and supply the test
297 bytecode:</p>
298
299 <pre>
300   <b>lli</b> -load=safe.so test.bc [program options]
301 </pre></li>  
302
303 </ol>
304
305 </div>
306
307 <!-- *********************************************************************** -->
308
309 <hr>
310 <div class="doc_footer">
311   <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
312   <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
313   <br>
314   Last modified: $Date$
315 </div>
316
317 </body>
318 </html>