1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <title>How to submit an LLVM bug report</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
10 <div class="doc_title">
11 How to submit an LLVM bug report
14 <table border="0" width="100%">
19 <li><a href="#introduction">Introduction - Got bugs?</a></li>
20 <li><a href="#crashers">Crashing Bugs</a>
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>
27 <li><a href="#miscompilations">Miscompilations</a></li>
28 <li><a href="#codegen">Incorrect code generation (JIT and LLC)</a></li>
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>
39 <img src="Debugging.gif" alt="Debugging" width="444" height="314">
44 <!-- *********************************************************************** -->
45 <div class="doc_section">
46 <a name="introduction">Introduction - Got bugs?</a>
48 <!-- *********************************************************************** -->
50 <div class="doc_text">
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>
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
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
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
76 <p>Thanks for helping us make LLVM better!</p>
80 <!-- *********************************************************************** -->
81 <div class="doc_section">
82 <a name="crashers">Crashing Bugs</a>
84 <!-- *********************************************************************** -->
86 <div class="doc_text">
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>
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>
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>
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>
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>
115 <li>Otherwise, something really weird happened. Email the list with what you
116 have at this point.</li>
122 <!-- ======================================================================= -->
123 <div class="doc_subsection">
124 <a name="front-end">Front-end bugs</a>
127 <div class="doc_text">
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>
139 <!-- ======================================================================= -->
140 <div class="doc_subsection">
141 <a name="gccas">GCCAS bugs</a>
144 <div class="doc_text">
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>
151 <b>gccas</b> -debug-pass=Arguments < /dev/null -o - > /dev/null
154 <p>... which will print a list of arguments, indicating the list of passes that
155 <tt><b>gccas</b></tt> runs. Once you have the input file and the list of
156 passes, go to the section on <a href="#passes">debugging bugs in LLVM
161 <!-- ======================================================================= -->
162 <div class="doc_subsection">
163 <a name="gccld">GCCLD bugs</a>
166 <div class="doc_text">
168 <p>If you find that a bug crashes in the <tt><b>gccld</b></tt> stage of
169 compilation, gather all of the <tt>.o</tt> bytecode files and libraries that are
170 being linked together (the "<tt><b>llvm-gcc</b> -v</tt>" output should include
171 the full list of objects linked). Then run:</p>
174 <b>llvm-as</b> < /dev/null > null.bc
175 <b>gccld</b> -debug-pass=Arguments null.bc
178 <p>... which will print a list of arguments, indicating the list of passes that
179 <tt><b>gccld</b></tt> runs. Once you have the input files and the list of
180 passes, go to the section on <a href="#passes">debugging bugs in LLVM
185 <!-- ======================================================================= -->
186 <div class="doc_subsection">
187 <a name="passes">Bugs in LLVM passes</a>
190 <div class="doc_text">
192 <p>At this point, you should have some number of LLVM assembly files or bytecode
193 files and a list of passes which crash when run on the specified input. In
194 order to reduce the list of passes (which is probably large) and the input to
195 something tractable, use the <tt><b>bugpoint</b></tt> tool as follows:</p>
198 <b>bugpoint</b> <input files> <list of passes>
201 <p><tt><b>bugpoint</b></tt> will print a bunch of output as it reduces the
202 test-case, but it should eventually print something like this:</p>
206 Emitted bytecode to 'bugpoint-reduced-simplified.bc'
208 *** You can reproduce the problem with: opt bugpoint-reduced-simplified.bc -licm
211 <p>Once you complete this, please send the LLVM bytecode file and the command
212 line to reproduce the problem to the llvmbugs mailing list.</p>
216 <!-- *********************************************************************** -->
217 <div class="doc_section">
218 <a name="miscompilations">Miscompilations</a>
220 <!-- *********************************************************************** -->
222 <div class="doc_text">
224 <p>A miscompilation occurs when a pass does not correctly transform a program,
225 thus producing errors that are only noticed during execution. This is different
226 from producing invalid LLVM code (i.e., code not in SSA form, using values
227 before defining them, etc.) which the verifier will check for after a pass
228 finishes its run.</p>
230 <p>To debug a miscompilation, you should choose which program you wish to run
231 the output through, e.g. C backend, the JIT, or LLC, and a selection of passes,
232 one of which may be causing the error, and run, for example:</p>
235 <b>bugpoint</b> -run-cbe [... optimization passes ...] file-to-test.bc
238 <p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass
239 that causes an error, and simplify the bytecode file as much as it can to assist
240 you. It will print a message letting you know how to reproduce the resulting
245 <!-- *********************************************************************** -->
246 <div class="doc_section">
247 <a name="codegen">Incorrect code generation</a>
249 <!-- *********************************************************************** -->
251 <div class="doc_text">
253 <p>Similarly to debugging incorrect compilation by mis-behaving passes, you can
254 debug incorrect code generation by either LLC or the JIT, using
255 <tt>bugpoint</tt>. The process <tt>bugpoint</tt> follows in this case is to try
256 to narrow the code down to a function that is miscompiled by one or the other
257 method, but since for correctness, the entire program must be run,
258 <tt>bugpoint</tt> will compile the code it deems to not be affected with the C
259 Backend, and then link in the shared object it generates.</p>
261 <p>To debug the JIT:</p>
264 <b>bugpoint</b> -run-jit -output=[correct output file] [bytecodefile]
267 <p>Similarly, to debug the LLC, one would run:</p>
270 <b>bugpoint</b> -run-llc -output=[correct output file] [bytecodefile]
273 <p>At the end of a successful <tt>bugpoint</tt> run, you will be presented
274 with two bytecode files: a <em>safe</em> file which can be compiled with the C
275 backend and the <em>test</em> file which either LLC or the JIT
276 mis-codegenerates, and thus causes the error.</p>
278 <p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do
283 <li>Regenerate the shared object from the safe bytecode file:<br>
286 <b>llc</b> -march=c safe.bc -o safe.c<br>
287 <b>gcc</b> -shared safe.c -o safe.so
290 <li>If debugging LLC, compile test bytecode native and link with the shared object:<br>
293 <b>llc</b> test.bc -o test.s -f<br>
294 gcc test.s safe.so -o test.llc<br>
295 ./test.llc [program options]
298 <li>If debugging the JIT, load the shared object and supply the test
302 <b>lli</b> -load=safe.so test.bc [program options]
309 <!-- *********************************************************************** -->
312 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
313 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
314 <a href="http://validator.w3.org/check/referer"><img
315 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
317 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
318 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
320 Last modified: $Date$