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