blob: b94479594d0ccc6fa038c8588ebb2b7be65fe0db [file] [log] [blame]
Misha Brukmanff919402003-10-31 18:37:20 +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>
Chris Lattner9525a332003-05-21 22:21:07 +00009
Misha Brukmanff919402003-10-31 18:37:20 +000010<div class="doc_title">
11 How to submit an LLVM bug report
12</div>
Chris Lattner9525a332003-05-21 22:21:07 +000013
Misha Brukmanff919402003-10-31 18:37:20 +000014<table border="0" width="100%">
15<tr>
16<td valign="top">
17
Chris Lattner9525a332003-05-21 22:21:07 +000018<ol>
Misha Brukmanff919402003-10-31 18:37:20 +000019 <li><a href="#introduction">Introduction - Got bugs?</a></li>
Chris Lattner9525a332003-05-21 22:21:07 +000020 <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>
Misha Brukmanff919402003-10-31 18:37:20 +000026 </ul></li>
27 <li><a href="#miscompilations">Miscompilations</a></li>
28 <li><a href="#codegen">Incorrect code generation (JIT and LLC)</a></li>
Chris Lattner9525a332003-05-21 22:21:07 +000029
Misha Brukmanff919402003-10-31 18:37:20 +000030</ol>
31
Misha Brukman67db86a2004-01-15 19:03:47 +000032<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>
Misha Brukmanff919402003-10-31 18:37:20 +000036
37</td>
38<td align="right">
Misha Brukman3c1f8e72004-05-12 21:26:16 +000039 <img src="img/Debugging.gif" alt="Debugging" width="444" height="314">
Misha Brukmanff919402003-10-31 18:37:20 +000040</td>
41</tr>
Chris Lattner9525a332003-05-21 22:21:07 +000042</table>
43
Chris Lattner9525a332003-05-21 22:21:07 +000044<!-- *********************************************************************** -->
Misha Brukmanff919402003-10-31 18:37:20 +000045<div class="doc_section">
46 <a name="introduction">Introduction - Got bugs?</a>
47</div>
Chris Lattner9525a332003-05-21 22:21:07 +000048<!-- *********************************************************************** -->
49
Misha Brukmanff919402003-10-31 18:37:20 +000050<div class="doc_text">
Chris Lattner9525a332003-05-21 22:21:07 +000051
Misha Brukmanff919402003-10-31 18:37:20 +000052<p>If you're working with LLVM and run into a bug, we definitely want to know
53about it. This document describes what you can do to increase the odds of
54getting it fixed quickly.</p>
55
56<p>Basically you have to do two things at a minimum. First, decide whether the
57bug <a href="#crashers">crashes the compiler</a> (or an LLVM pass), or if the
Chris Lattner9525a332003-05-21 22:21:07 +000058compiler is <a href="#miscompilations">miscompiling</a> the program. Based on
59what type of bug it is, follow the instructions in the linked section to narrow
60down the bug so that the person who fixes it will be able to find the problem
Misha Brukmanff919402003-10-31 18:37:20 +000061more easily.</p>
Chris Lattner9525a332003-05-21 22:21:07 +000062
Misha Brukmanff919402003-10-31 18:37:20 +000063<p>Once you have a reduced test-case, go to <a
64href="http://llvm.cs.uiuc.edu/bugs/enter_bug.cgi">the LLVM Bug Tracking
65System</a>, select the category in which the bug falls, and fill out the form
66with the necessary details. The bug description should contain the following
67information:</p>
68
John Criswell56a850a2003-10-22 15:06:11 +000069<ul>
Misha Brukmanb00e1062003-10-22 17:01:44 +000070 <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>
John Criswell56a850a2003-10-22 15:06:11 +000074</ul>
75
Misha Brukmanff919402003-10-31 18:37:20 +000076<p>Thanks for helping us make LLVM better!</p>
Chris Lattner9525a332003-05-21 22:21:07 +000077
Misha Brukmanff919402003-10-31 18:37:20 +000078</div>
Chris Lattner9525a332003-05-21 22:21:07 +000079
80<!-- *********************************************************************** -->
Misha Brukmanff919402003-10-31 18:37:20 +000081<div class="doc_section">
82 <a name="crashers">Crashing Bugs</a>
83</div>
Chris Lattner9525a332003-05-21 22:21:07 +000084<!-- *********************************************************************** -->
85
Misha Brukmanff919402003-10-31 18:37:20 +000086<div class="doc_text">
87
88<p>More often than not, bugs in the compiler cause it to crash - often due to an
Chris Lattner9525a332003-05-21 22:21:07 +000089assertion 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
92piece of the puzzle is to figure out if it is the GCC-based front-end that is
Misha Brukmanff919402003-10-31 18:37:20 +000093buggy or if it's one of the LLVM tools that has problems.</p>
Chris Lattner9525a332003-05-21 22:21:07 +000094
Misha Brukmanff919402003-10-31 18:37:20 +000095<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
98add a <tt>-v</tt> option to the command line. The compiler will print out a
John Criswellfaba4622004-03-12 20:42:16 +000099bunch 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>
Chris Lattner9525a332003-05-21 22:21:07 +0000102
103<ul>
Chris Lattner9525a332003-05-21 22:21:07 +0000104
John Criswellfaba4622004-03-12 20:42:16 +0000105 <li>If <tt><b>cc1</b></tt> or <tt><b>cc1plus</b></tt> crashed, you found a
106 problem with the front-end.
Misha Brukmanff919402003-10-31 18:37:20 +0000107 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>
Chris Lattner9525a332003-05-21 22:21:07 +0000121
122<!-- ======================================================================= -->
Misha Brukmanff919402003-10-31 18:37:20 +0000123<div class="doc_subsection">
124 <a name="front-end">Front-end bugs</a>
125</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000126
Misha Brukmanff919402003-10-31 18:37:20 +0000127<div class="doc_text">
128
129<p>If the problem is in the front-end, you should re-run the same
Brian Gaeke627b9f42003-05-23 21:03:50 +0000130<tt>llvm-gcc</tt> command that resulted in the crash, but add the
Misha Brukmanff919402003-10-31 18:37:20 +0000131<tt>-save-temps</tt> option. The compiler will crash again, but it will leave
132behind a <tt><i>foo</i>.i</tt> file (containing preprocessed C source code) and
133possibly <tt><i>foo</i>.s</tt> (containing LLVM assembly code), for each
134compiled <tt><i>foo</i>.c</tt> file. Send us the <tt><i>foo</i>.i</tt> file,
135along with a brief description of the error it caused.</p>
136
137</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000138
139<!-- ======================================================================= -->
Misha Brukmanff919402003-10-31 18:37:20 +0000140<div class="doc_subsection">
141 <a name="gccas">GCCAS bugs</a>
142</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000143
Misha Brukmanff919402003-10-31 18:37:20 +0000144<div class="doc_text">
145
146<p>If you find that a bug crashes in the <tt><b>gccas</b></tt> stage of
Brian Gaeke627b9f42003-05-23 21:03:50 +0000147compilation, compile your test-case to a <tt>.s</tt> file with the
Misha Brukmanff919402003-10-31 18:37:20 +0000148<tt>-save-temps</tt> option to <tt><b>llvm-gcc</b></tt>. Then run:</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000149
Misha Brukmanc21921c2004-04-15 20:49:32 +0000150<div class="doc_code">
Misha Brukman67abadb2004-05-14 19:04:07 +0000151<pre><b>gccas</b> -debug-pass=Arguments &lt; /dev/null -o - &gt; /dev/null</pre>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000152</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000153
Misha Brukmanff919402003-10-31 18:37:20 +0000154<p>... which will print a list of arguments, indicating the list of passes that
Chris Lattner9525a332003-05-21 22:21:07 +0000155<tt><b>gccas</b></tt> runs. Once you have the input file and the list of
156passes, go to the section on <a href="#passes">debugging bugs in LLVM
Misha Brukmanff919402003-10-31 18:37:20 +0000157passes</a>.</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000158
Misha Brukmanff919402003-10-31 18:37:20 +0000159</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000160
161<!-- ======================================================================= -->
Misha Brukmanff919402003-10-31 18:37:20 +0000162<div class="doc_subsection">
163 <a name="gccld">GCCLD bugs</a>
164</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000165
Misha Brukmanff919402003-10-31 18:37:20 +0000166<div class="doc_text">
167
168<p>If you find that a bug crashes in the <tt><b>gccld</b></tt> stage of
Chris Lattner9525a332003-05-21 22:21:07 +0000169compilation, gather all of the <tt>.o</tt> bytecode files and libraries that are
170being linked together (the "<tt><b>llvm-gcc</b> -v</tt>" output should include
Misha Brukmanff919402003-10-31 18:37:20 +0000171the full list of objects linked). Then run:</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000172
Misha Brukmanc21921c2004-04-15 20:49:32 +0000173<div class="doc_code">
Misha Brukman67abadb2004-05-14 19:04:07 +0000174<pre>
175<b>llvm-as</b> &lt; /dev/null &gt; null.bc
176<b>gccld</b> -debug-pass=Arguments null.bc</tt></p>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000177</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000178
Misha Brukmanff919402003-10-31 18:37:20 +0000179<p>... which will print a list of arguments, indicating the list of passes that
Chris Lattner9525a332003-05-21 22:21:07 +0000180<tt><b>gccld</b></tt> runs. Once you have the input files and the list of
181passes, go to the section on <a href="#passes">debugging bugs in LLVM
Misha Brukmanff919402003-10-31 18:37:20 +0000182passes</a>.</p>
183
184</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000185
186<!-- ======================================================================= -->
Misha Brukmanff919402003-10-31 18:37:20 +0000187<div class="doc_subsection">
188 <a name="passes">Bugs in LLVM passes</a>
189</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000190
Misha Brukmanff919402003-10-31 18:37:20 +0000191<div class="doc_text">
192
193<p>At this point, you should have some number of LLVM assembly files or bytecode
Chris Lattner9525a332003-05-21 22:21:07 +0000194files and a list of passes which crash when run on the specified input. In
195order to reduce the list of passes (which is probably large) and the input to
Misha Brukmanff919402003-10-31 18:37:20 +0000196something tractable, use the <tt><b>bugpoint</b></tt> tool as follows:</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000197
Misha Brukmanc21921c2004-04-15 20:49:32 +0000198<div class="doc_code">
Misha Brukman67abadb2004-05-14 19:04:07 +0000199<pre><b>bugpoint</b> &lt;input files&gt; &lt;list of passes&gt;</pre>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000200</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000201
Misha Brukmanff919402003-10-31 18:37:20 +0000202<p><tt><b>bugpoint</b></tt> will print a bunch of output as it reduces the
203test-case, but it should eventually print something like this:</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000204
Misha Brukman4825e212004-04-19 03:07:29 +0000205<div class="doc_code">
Chris Lattner9525a332003-05-21 22:21:07 +0000206<pre>
Misha Brukman4825e212004-04-19 03:07:29 +0000207...
208Emitted bytecode to 'bugpoint-reduced-simplified.bc'
Chris Lattner9525a332003-05-21 22:21:07 +0000209
Misha Brukman4825e212004-04-19 03:07:29 +0000210*** You can reproduce the problem with: opt bugpoint-reduced-simplified.bc -licm
Misha Brukmanff919402003-10-31 18:37:20 +0000211</pre>
Misha Brukman4825e212004-04-19 03:07:29 +0000212</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000213
Misha Brukmanff919402003-10-31 18:37:20 +0000214<p>Once you complete this, please send the LLVM bytecode file and the command
215line to reproduce the problem to the llvmbugs mailing list.</p>
Chris Lattner9525a332003-05-21 22:21:07 +0000216
Misha Brukmanff919402003-10-31 18:37:20 +0000217</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000218
219<!-- *********************************************************************** -->
Misha Brukmanff919402003-10-31 18:37:20 +0000220<div class="doc_section">
221 <a name="miscompilations">Miscompilations</a>
222</div>
Chris Lattner9525a332003-05-21 22:21:07 +0000223<!-- *********************************************************************** -->
224
Misha Brukmanff919402003-10-31 18:37:20 +0000225<div class="doc_text">
Chris Lattner9525a332003-05-21 22:21:07 +0000226
Misha Brukmanff919402003-10-31 18:37:20 +0000227<p>A miscompilation occurs when a pass does not correctly transform a program,
228thus producing errors that are only noticed during execution. This is different
229from producing invalid LLVM code (i.e., code not in SSA form, using values
230before defining them, etc.) which the verifier will check for after a pass
231finishes its run.</p>
232
Chris Lattner41553242004-05-11 19:34:27 +0000233<p>If it looks like the LLVM compiler is miscompiling a program, the very first
Misha Brukmanb797a4f2004-05-12 00:57:24 +0000234thing to check is to make sure it is not using undefined behavior. In
235particular, check to see if the program <a
236href="http://valgrind.kde.org/">valgrind</a>s clean, passes purify, or some
Chris Lattner41553242004-05-11 19:34:27 +0000237other memory checker tool. Many of the "LLVM bugs" that we have chased down
238ended 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
241which code generator you wish to compile the program with (e.g. C backend, the
242JIT, or LLC) and optionally a series of LLVM passes to run. For example:</p>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000243
Misha Brukmanc21921c2004-04-15 20:49:32 +0000244<div class="doc_code">
Misha Brukman67abadb2004-05-14 19:04:07 +0000245<pre>
246<b>bugpoint</b> -run-cbe [... optimization passes ...] file-to-test.bc --args -- [program arguments]</pre>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000247</div>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000248
Misha Brukmanff919402003-10-31 18:37:20 +0000249<p><tt>bugpoint</tt> will try to narrow down your list of passes to the one pass
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000250that causes an error, and simplify the bytecode file as much as it can to assist
251you. It will print a message letting you know how to reproduce the resulting
Misha Brukmanff919402003-10-31 18:37:20 +0000252error.</p>
253
254</div>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000255
256<!-- *********************************************************************** -->
Misha Brukmanff919402003-10-31 18:37:20 +0000257<div class="doc_section">
258 <a name="codegen">Incorrect code generation</a>
259</div>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000260<!-- *********************************************************************** -->
261
Misha Brukmanff919402003-10-31 18:37:20 +0000262<div class="doc_text">
263
264<p>Similarly to debugging incorrect compilation by mis-behaving passes, you can
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000265debug 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
267to narrow the code down to a function that is miscompiled by one or the other
268method, 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
Misha Brukmanff919402003-10-31 18:37:20 +0000270Backend, and then link in the shared object it generates.</p>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000271
Misha Brukmanff919402003-10-31 18:37:20 +0000272<p>To debug the JIT:</p>
273
Misha Brukmanc21921c2004-04-15 20:49:32 +0000274<div class="doc_code">
Misha Brukmanc050f9f2004-05-14 18:57:24 +0000275<pre>
276bugpoint -run-jit -output=[correct output file] [bytecode file] \
277 --tool-args -- [arguments to pass to lli] \
278 --args -- [program arguments]
279</pre>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000280</div>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000281
Misha Brukmanff919402003-10-31 18:37:20 +0000282<p>Similarly, to debug the LLC, one would run:</p>
283
Misha Brukmanc21921c2004-04-15 20:49:32 +0000284<div class="doc_code">
Misha Brukmanc050f9f2004-05-14 18:57:24 +0000285<pre>
286bugpoint -run-llc -output=[correct output file] [bytecode file] \
287 --tool-args -- [arguments to pass to llc] \
288 --args -- [program arguments]
289</pre>
Misha Brukmanc21921c2004-04-15 20:49:32 +0000290</div>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000291
Misha Brukman272322e2004-04-15 21:01:21 +0000292<p><b>Special note:</b> if you are debugging MultiSource or SPEC tests that
293already exist in the <tt>llvm/test</tt> hierarchy, there is an easier way to
294debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which
295will pass the program options specified in the Makefiles:</p>
296
297<div class="doc_code">
Misha Brukman67abadb2004-05-14 19:04:07 +0000298<pre>
299cd llvm/test/../../program
300make bugpoint-jit
301</pre>
Misha Brukman272322e2004-04-15 21:01:21 +0000302</div>
303
Misha Brukmanff919402003-10-31 18:37:20 +0000304<p>At the end of a successful <tt>bugpoint</tt> run, you will be presented
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000305with two bytecode files: a <em>safe</em> file which can be compiled with the C
306backend and the <em>test</em> file which either LLC or the JIT
Misha Brukmanff919402003-10-31 18:37:20 +0000307mis-codegenerates, and thus causes the error.</p>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000308
Misha Brukmanff919402003-10-31 18:37:20 +0000309<p>To reproduce the error that <tt>bugpoint</tt> found, it is sufficient to do
310the following:</p>
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000311
312<ol>
Misha Brukmanff919402003-10-31 18:37:20 +0000313
Misha Brukman67abadb2004-05-14 19:04:07 +0000314<li><p>Regenerate the shared object from the safe bytecode file:</p>
Misha Brukmanff919402003-10-31 18:37:20 +0000315
Misha Brukman67abadb2004-05-14 19:04:07 +0000316<div class="doc_code">
317<pre>
318<b>llc</b> -march=c safe.bc -o safe.c
319<b>gcc</b> -shared safe.c -o safe.so
320</pre>
321</div></li>
Misha Brukmanff919402003-10-31 18:37:20 +0000322
Misha Brukman67abadb2004-05-14 19:04:07 +0000323<li><p>If debugging LLC, compile test bytecode native and link with the shared
324 object:</p>
Misha Brukmanff919402003-10-31 18:37:20 +0000325
Misha Brukman67abadb2004-05-14 19:04:07 +0000326<div class="doc_code">
327<pre>
328<b>llc</b> test.bc -o test.s -f
329<b>gcc</b> test.s safe.so -o test.llc
330./test.llc [program options]
331</pre>
332</div></li>
333
334<li><p>If debugging the JIT, load the shared object and supply the test
335 bytecode:</p>
Misha Brukmanff919402003-10-31 18:37:20 +0000336
Misha Brukman67abadb2004-05-14 19:04:07 +0000337<div class="doc_code">
338<pre><b>lli</b> -load=safe.so test.bc [program options]</pre>
339</div></li>
Misha Brukmanff919402003-10-31 18:37:20 +0000340
Misha Brukmana3fc5d92003-09-17 18:51:47 +0000341</ol>
Chris Lattner9525a332003-05-21 22:21:07 +0000342
Misha Brukmanff919402003-10-31 18:37:20 +0000343</div>
344
Chris Lattner9525a332003-05-21 22:21:07 +0000345<!-- *********************************************************************** -->
Misha Brukmanff919402003-10-31 18:37:20 +0000346<hr>
Misha Brukman67db86a2004-01-15 19:03:47 +0000347<address>
348 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
349 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
350 <a href="http://validator.w3.org/check/referer"><img
351 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
352
353 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Misha Brukmanff919402003-10-31 18:37:20 +0000354 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a>
355 <br>
356 Last modified: $Date$
Misha Brukman67db86a2004-01-15 19:03:47 +0000357</address>
Misha Brukmanff919402003-10-31 18:37:20 +0000358
359</body>
360</html>