1==================================
2Contributing to LLVM
3==================================
4
5
6Thank you for your interest in contributing to LLVM! There are multiple ways to
7contribute, and we appreciate all contributions. In case you
8have questions, you can either use the `Forum`_
9or the #llvm channel on `irc.oftc.net`_.
10
11If you want to contribute code, please familiarize yourself with the :doc:`DeveloperPolicy`.
12
13.. contents::
14  :local:
15
16
17Ways to Contribute
18==================
19
20Bug Reports
21-----------
22If you are working with LLVM and run into a bug, we definitely want to know
23about it. Please let us know and follow the instructions in
24:doc:`HowToSubmitABug`  to create a bug report.
25
26Bug Fixes
27---------
28If you are interested in contributing code to LLVM, bugs labeled with the
29`good first issue`_ keyword in the `bug tracker`_ are a good way to get familiar with
30the code base. If you are interested in fixing a bug please comment on it to
31let people know you are working on it.
32
33Then try to reproduce and fix the bug with upstream LLVM. Start by building
34LLVM from source as described in :doc:`GettingStarted` and
35use the built binaries to reproduce the failure described in the bug. Use
36a debug build (`-DCMAKE_BUILD_TYPE=Debug`) or a build with assertions
37(`-DLLVM_ENABLE_ASSERTIONS=On`, enabled for Debug builds).
38
39Reporting a Security Issue
40--------------------------
41
42There is a separate process to submit security-related bugs, see :ref:`report-security-issue`.
43
44Bigger Pieces of Work
45---------------------
46In case you are interested in taking on a bigger piece of work, a list of
47interesting projects is maintained at the `LLVM's Open Projects page`_. In case
48you are interested in working on any of these projects, please post on the
49`Forum`_, so that we know the project is being worked on.
50
51.. _submit_patch:
52
53How to Submit a Patch
54=====================
55Once you have a patch ready, it is time to submit it. The patch should:
56
57* include a small unit test
58* conform to the :doc:`CodingStandards`. You can use the `clang-format-diff.py`_ or `git-clang-format`_ tools to automatically format your patch properly.
59* not contain any unrelated changes
60* be an isolated change. Independent changes should be submitted as separate patches as this makes reviewing easier.
61* have a single commit (unless stacked on another Differential), up-to-date with the upstream ``origin/main`` branch, and don't have merges.
62
63.. _format patches:
64
65Before sending a patch for review, please also try to ensure it is
66formatted properly. We use ``clang-format`` for this, which has git integration
67through the ``git-clang-format`` script. On some systems, it may already be
68installed (or be installable via your package manager). If so, you can simply
69run it -- the following command will format only the code changed in the most
70recent commit:
71
72.. code-block:: console
73
74  % git clang-format HEAD~1
75
76Note that this modifies the files, but doesn't commit them -- you'll likely want
77to run
78
79.. code-block:: console
80
81  % git commit --amend -a
82
83in order to update the last commit with all pending changes.
84
85.. note::
86  If you don't already have ``clang-format`` or ``git clang-format`` installed
87  on your system, the ``clang-format`` binary will be built alongside clang, and
88  the git integration can be run from
89  ``clang/tools/clang-format/git-clang-format``.
90
91We don't currently accept GitHub pull requests, and you'll need to send patches
92via :ref:`Phabricator#phabricator-reviews <phabricator-reviews>`.
93(We used to allow patches on the llvm-commits mailing list, but the mailing lists
94have been deprecated.)
95
96To make sure the right people see your patch, please select suitable reviewers
97and add them to your patch when requesting a review. Suitable reviewers are the
98code owner (see CODE_OWNERS.txt) and other people doing work in the area your
99patch touches. If you are using Phabricator, add them to the `Reviewers` field
100when creating a review and if you are using `llvm-commits`, add them to the CC of
101your email.
102
103A reviewer may request changes or ask questions during the review. If you are
104uncertain on how to provide test cases, documentation, etc., feel free to ask
105for guidance during the review. Please address the feedback and re-post an
106updated version of your patch. This cycle continues until all requests and comments
107have been addressed and a reviewer accepts the patch with a `Looks good to me` or `LGTM`.
108Once that is done the change can be committed. If you do not have commit
109access, please let people know during the review and someone should commit it
110on your behalf.
111
112If you have received no comments on your patch for a week, you can request a
113review by 'ping'ing a patch by responding to the email thread containing the
114patch, or the Phabricator review with "Ping." The common courtesy 'ping' rate
115is once a week. Please remember that you are asking for valuable time from other
116professional developers.
117
118For more information on LLVM's code-review process, please see :doc:`CodeReview`.
119
120.. _commit_from_git:
121
122For developers to commit changes from Git
123-----------------------------------------
124
125Once a patch is reviewed, you should rebase it, re-test locally, and commit the
126changes to LLVM's main branch. This is done using `git push` if you have the
127required access rights. See `committing a change
128<Phabricator.html#committing-a-change>`_ for Phabricator based commits or
129`obtaining commit access <DeveloperPolicy.html#obtaining-commit-access>`_
130for commit access.
131
132Here is an example workflow using git. This workflow assumes you have an
133accepted commit on the branch named `branch-with-change`.
134
135.. code-block:: console
136
137  # Pull changes from the upstream main branch.
138  % git checkout main && git pull
139  # Rebase your change onto main.
140  % git rebase --onto main --root branch-with-change
141  # Rerun the appropriate tests if needed.
142  % ninja check-$whatever
143  # Check that the list of commits about to be pushed is correct.
144  % git log origin/main...HEAD --oneline
145  # Push to Github.
146  % git push origin HEAD:main
147
148LLVM currently has a linear-history policy, which means that merge commits are
149not allowed. The `llvm-project` repo on github is configured to reject pushes
150that include merges, so the `git rebase` step above is required.
151
152Please ask for help if you're having trouble with your particular git workflow.
153
154.. _git_pre_push_hook:
155
156Git pre-push hook
157^^^^^^^^^^^^^^^^^
158
159We include an optional pre-push hook that run some sanity checks on the revisions
160you are about to push and ask confirmation if you push multiple commits at once.
161You can set it up (on Unix systems) by running from the repository root:
162
163.. code-block:: console
164
165  % ln -sf ../../llvm/utils/git/pre-push.py .git/hooks/pre-push
166
167Helpful Information About LLVM
168==============================
169:doc:`LLVM's documentation <index>` provides a wealth of information about LLVM's internals as
170well as various user guides. The pages listed below should provide a good overview
171of LLVM's high-level design, as well as its internals:
172
173:doc:`GettingStarted`
174   Discusses how to get up and running quickly with the LLVM infrastructure.
175   Everything from unpacking and compilation of the distribution to execution
176   of some tools.
177
178:doc:`LangRef`
179  Defines the LLVM intermediate representation.
180
181:doc:`ProgrammersManual`
182  Introduction to the general layout of the LLVM sourcebase, important classes
183  and APIs, and some tips & tricks.
184
185`LLVM for Grad Students`__
186  This is an introduction to the LLVM infrastructure by Adrian Sampson. While it
187  has been written for grad students, it provides  a good, compact overview of
188  LLVM's architecture, LLVM's IR and how to write a new pass.
189
190  .. __: http://www.cs.cornell.edu/~asampson/blog/llvm.html
191
192`Intro to LLVM`__
193  Book chapter providing a compiler hacker's introduction to LLVM.
194
195  .. __: http://www.aosabook.org/en/llvm.html
196
197.. _Forum: https://discourse.llvm.org
198.. _irc.oftc.net: irc://irc.oftc.net/llvm
199.. _good first issue: https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22
200.. _bug tracker: https://github.com/llvm/llvm-project/issues
201.. _clang-format-diff.py: https://reviews.llvm.org/source/llvm-github/browse/main/clang/tools/clang-format/clang-format-diff.py
202.. _git-clang-format: https://reviews.llvm.org/source/llvm-github/browse/main/clang/tools/clang-format/git-clang-format
203.. _LLVM's Phabricator: https://reviews.llvm.org/
204.. _LLVM's Open Projects page: https://llvm.org/OpenProjects.html#what
205