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