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