remove the rest of the "written by" lines in the documentation. It is
[oota-llvm.git] / docs / HowToSubmitABug.rst
1 .. _how-to-submit-a-bug-report:
2
3 ================================
4 How to submit an LLVM bug report
5 ================================
6
7 Introduction - Got bugs?
8 ========================
9
10
11 If you're working with LLVM and run into a bug, we definitely want to know
12 about it.  This document describes what you can do to increase the odds of
13 getting it fixed quickly.
14
15 Basically you have to do two things at a minimum.  First, decide whether
16 the bug `crashes the compiler`_ (or an LLVM pass), or if the
17 compiler is `miscompiling`_ the program (i.e., the
18 compiler successfully produces an executable, but it doesn't run right).
19 Based on what type of bug it is, follow the instructions in the linked
20 section to narrow down the bug so that the person who fixes it will be able
21 to find the problem more easily.
22
23 Once you have a reduced test-case, go to `the LLVM Bug Tracking System
24 <http://llvm.org/bugs/enter_bug.cgi>`_ and fill out the form with the
25 necessary details (note that you don't need to pick a category, just use
26 the "new-bugs" category if you're not sure).  The bug description should
27 contain the following information:
28
29 * All information necessary to reproduce the problem.
30 * The reduced test-case that triggers the bug.
31 * The location where you obtained LLVM (if not from our Subversion
32   repository).
33
34 Thanks for helping us make LLVM better!
35
36 .. _crashes the compiler:
37
38 Crashing Bugs
39 =============
40
41 More often than not, bugs in the compiler cause it to crash---often due to
42 an assertion failure of some sort. The most important piece of the puzzle
43 is to figure out if it is crashing in the GCC front-end or if it is one of
44 the LLVM libraries (e.g. the optimizer or code generator) that has
45 problems.
46
47 To figure out which component is crashing (the front-end, optimizer or code
48 generator), run the ``llvm-gcc`` command line as you were when the crash
49 occurred, but with the following extra command line options:
50
51 * ``-O0 -emit-llvm``: If ``llvm-gcc`` still crashes when passed these
52   options (which disable the optimizer and code generator), then the crash
53   is in the front-end.  Jump ahead to the section on :ref:`front-end bugs
54   <front-end>`.
55
56 * ``-emit-llvm``: If ``llvm-gcc`` crashes with this option (which disables
57   the code generator), you found an optimizer bug.  Jump ahead to
58   `compile-time optimization bugs`_.
59
60 * Otherwise, you have a code generator crash. Jump ahead to `code
61   generator bugs`_.
62
63 .. _front-end bug:
64 .. _front-end:
65
66 Front-end bugs
67 --------------
68
69 If the problem is in the front-end, you should re-run the same ``llvm-gcc``
70 command that resulted in the crash, but add the ``-save-temps`` option.
71 The compiler will crash again, but it will leave behind a ``foo.i`` file
72 (containing preprocessed C source code) and possibly ``foo.s`` for each
73 compiled ``foo.c`` file. Send us the ``foo.i`` file, along with the options
74 you passed to ``llvm-gcc``, and a brief description of the error it caused.
75
76 The `delta <http://delta.tigris.org/>`_ tool helps to reduce the
77 preprocessed file down to the smallest amount of code that still replicates
78 the problem. You're encouraged to use delta to reduce the code to make the
79 developers' lives easier. `This website
80 <http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction>`_ has instructions
81 on the best way to use delta.
82
83 .. _compile-time optimization bugs:
84
85 Compile-time optimization bugs
86 ------------------------------
87
88 If you find that a bug crashes in the optimizer, compile your test-case to a
89 ``.bc`` file by passing "``-emit-llvm -O0 -c -o foo.bc``".
90 Then run:
91
92 .. code-block:: bash
93
94    opt -std-compile-opts -debug-pass=Arguments foo.bc -disable-output
95
96 This command should do two things: it should print out a list of passes, and
97 then it should crash in the same way as llvm-gcc.  If it doesn't crash, please
98 follow the instructions for a `front-end bug`_.
99
100 If this does crash, then you should be able to debug this with the following
101 bugpoint command:
102
103 .. code-block:: bash
104
105    bugpoint foo.bc <list of passes printed by opt>
106
107 Please run this, then file a bug with the instructions and reduced .bc
108 files that bugpoint emits.  If something goes wrong with bugpoint, please
109 submit the "foo.bc" file and the list of passes printed by ``opt``.
110
111 .. _code generator bugs:
112
113 Code generator bugs
114 -------------------
115
116 If you find a bug that crashes llvm-gcc in the code generator, compile your
117 source file to a .bc file by passing "``-emit-llvm -c -o foo.bc``" to
118 llvm-gcc (in addition to the options you already pass).  Once your have
119 foo.bc, one of the following commands should fail:
120
121 #. ``llc foo.bc``
122 #. ``llc foo.bc -relocation-model=pic``
123 #. ``llc foo.bc -relocation-model=static``
124
125 If none of these crash, please follow the instructions for a `front-end
126 bug`_.  If one of these do crash, you should be able to reduce this with
127 one of the following bugpoint command lines (use the one corresponding to
128 the command above that failed):
129
130 #. ``bugpoint -run-llc foo.bc``
131 #. ``bugpoint -run-llc foo.bc --tool-args -relocation-model=pic``
132 #. ``bugpoint -run-llc foo.bc --tool-args -relocation-model=static``
133
134 Please run this, then file a bug with the instructions and reduced .bc file
135 that bugpoint emits.  If something goes wrong with bugpoint, please submit
136 the "foo.bc" file and the option that llc crashes with.
137
138 .. _miscompiling:
139
140 Miscompilations
141 ===============
142
143 If llvm-gcc successfully produces an executable, but that executable
144 doesn't run right, this is either a bug in the code or a bug in the
145 compiler.  The first thing to check is to make sure it is not using
146 undefined behavior (e.g. reading a variable before it is defined). In
147 particular, check to see if the program `valgrind
148 <http://valgrind.org/>`_'s clean, passes purify, or some other memory
149 checker tool. Many of the "LLVM bugs" that we have chased down ended up
150 being bugs in the program being compiled, not LLVM.
151
152 Once you determine that the program itself is not buggy, you should choose
153 which code generator you wish to compile the program with (e.g. LLC or the JIT)
154 and optionally a series of LLVM passes to run.  For example:
155
156 .. code-block:: bash
157
158    bugpoint -run-llc [... optzn passes ...] file-to-test.bc --args -- [program arguments]
159
160 bugpoint will try to narrow down your list of passes to the one pass that
161 causes an error, and simplify the bitcode file as much as it can to assist
162 you. It will print a message letting you know how to reproduce the
163 resulting error.
164
165 Incorrect code generation
166 =========================
167
168 Similarly to debugging incorrect compilation by mis-behaving passes, you
169 can debug incorrect code generation by either LLC or the JIT, using
170 ``bugpoint``. The process ``bugpoint`` follows in this case is to try to
171 narrow the code down to a function that is miscompiled by one or the other
172 method, but since for correctness, the entire program must be run,
173 ``bugpoint`` will compile the code it deems to not be affected with the C
174 Backend, and then link in the shared object it generates.
175
176 To debug the JIT:
177
178 .. code-block:: bash
179
180    bugpoint -run-jit -output=[correct output file] [bitcode file]  \
181             --tool-args -- [arguments to pass to lli]              \
182             --args -- [program arguments]
183
184 Similarly, to debug the LLC, one would run:
185
186 .. code-block:: bash
187
188    bugpoint -run-llc -output=[correct output file] [bitcode file]  \
189             --tool-args -- [arguments to pass to llc]              \
190             --args -- [program arguments]
191
192 **Special note:** if you are debugging MultiSource or SPEC tests that
193 already exist in the ``llvm/test`` hierarchy, there is an easier way to
194 debug the JIT, LLC, and CBE, using the pre-written Makefile targets, which
195 will pass the program options specified in the Makefiles:
196
197 .. code-block:: bash
198
199    cd llvm/test/../../program
200    make bugpoint-jit
201
202 At the end of a successful ``bugpoint`` run, you will be presented
203 with two bitcode files: a *safe* file which can be compiled with the C
204 backend and the *test* file which either LLC or the JIT
205 mis-codegenerates, and thus causes the error.
206
207 To reproduce the error that ``bugpoint`` found, it is sufficient to do
208 the following:
209
210 #. Regenerate the shared object from the safe bitcode file:
211
212    .. code-block:: bash
213
214       llc -march=c safe.bc -o safe.c
215       gcc -shared safe.c -o safe.so
216
217 #. If debugging LLC, compile test bitcode native and link with the shared
218    object:
219
220    .. code-block:: bash
221
222       llc test.bc -o test.s
223       gcc test.s safe.so -o test.llc
224       ./test.llc [program options]
225
226 #. If debugging the JIT, load the shared object and supply the test
227    bitcode:
228
229    .. code-block:: bash
230
231       lli -load=safe.so test.bc [program options]