HowToSubmitABug.rst 8.4 KB

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