xref: /llvm-project/llvm/docs/DeveloperPolicy.rst (revision 4b6fc4934685c26f223e435d62b02b60544f76d3)
1.. _developer_policy:
2
3=====================
4LLVM Developer Policy
5=====================
6
7.. contents::
8   :local:
9
10Introduction
11============
12
13This document contains the LLVM Developer Policy which defines the project's
14policy towards developers and their contributions. The intent of this policy is
15to eliminate miscommunication, rework, and confusion that might arise from the
16distributed nature of LLVM's development.  By stating the policy in clear terms,
17we hope each developer can know ahead of time what to expect when making LLVM
18contributions.  This policy covers all llvm.org subprojects, including Clang,
19LLDB, libc++, etc.
20
21This policy is also designed to accomplish the following objectives:
22
23#. Attract both users and developers to the LLVM project.
24
25#. Make life as simple and easy for contributors as possible.
26
27#. Keep the top of tree as stable as possible.
28
29#. Establish awareness of the project's :ref:`copyright, license, and patent
30   policies <copyright-license-patents>` with contributors to the project.
31
32This policy is aimed at frequent contributors to LLVM. People interested in
33contributing one-off patches can do so in an informal way by sending them to the
34`llvm-commits mailing list
35<http://lists.llvm.org/mailman/listinfo/llvm-commits>`_ and engaging another
36developer to see it through the process.
37
38Developer Policies
39==================
40
41This section contains policies that pertain to frequent LLVM developers.  We
42always welcome `one-off patches`_ from people who do not routinely contribute to
43LLVM, but we expect more from frequent contributors to keep the system as
44efficient as possible for everyone.  Frequent LLVM contributors are expected to
45meet the following requirements in order for LLVM to maintain a high standard of
46quality.
47
48Stay Informed
49-------------
50
51Developers should stay informed by reading the `LLVM Discourse forums`_ and subscribing
52to the categories of interest for notifications.
53
54Paying attention to changes being made by others is a good way to see what other people
55are interested in and watching the flow of the project as a whole.
56
57Contibutions to the project are made through :ref:`GitHub Pull Requests <github-reviews>`.
58You can subscribe to notification for areas of the codebase by joining
59one of the `pr-subscribers-* <https://github.com/orgs/llvm/teams?query=pr-subscribers>`_
60GitHub teams. This `mapping <https://github.com/llvm/llvm-project/blob/main/.github/new-prs-labeler.yml>`_
61indicates which team is associated with a particular paths in the repository.
62
63You can also subscribe to the "commits" mailing list for a subproject you're interested in,
64such as `llvm-commits
65<http://lists.llvm.org/mailman/listinfo/llvm-commits>`_, `cfe-commits
66<http://lists.llvm.org/mailman/listinfo/cfe-commits>`_, or `lldb-commits
67<http://lists.llvm.org/mailman/listinfo/lldb-commits>`_.
68
69Missing features and bugs are tracked through our `GitHub issue tracker <https://github.com/llvm/llvm-project/issues>`_
70and assigned labels. We recommend that active developers monitor incoming issues.
71You can subscribe for notification for specific components by joining
72one of the `issue-subscribers-* <https://github.com/orgs/llvm/teams?query=issue-subscribers>`_
73teams.
74You may also subscribe to the `llvm-bugs
75<http://lists.llvm.org/mailman/listinfo/llvm-bugs>`_ email list to keep track
76of bugs and enhancements occurring in the entire project.  We really appreciate people
77who are proactive at catching incoming bugs in their components and dealing with them
78promptly.
79
80Please be aware that all public LLVM mailing lists and discourse forums are public and archived, and
81that notices of confidentiality or non-disclosure cannot be respected.
82
83.. _patch:
84.. _one-off patches:
85
86Making and Submitting a Patch
87-----------------------------
88
89When making a patch for review, the goal is to make it as easy for the reviewer
90to read it as possible.  As such, we recommend that you:
91
92#. Make your patch against git main, not a branch, and not an old version
93   of LLVM.  This makes it easy to apply the patch.  For information on how to
94   clone from git, please see the :ref:`Getting Started Guide <sources>`.
95
96#. Similarly, patches should be submitted soon after they are generated.  Old
97   patches may not apply correctly if the underlying code changes between the
98   time the patch was created and the time it is applied.
99
100#. Once you have created your patch, create a
101   :ref:`GitHub Pull Request <github-reviews>` for
102   it (or commit it directly if applicable).
103
104When submitting patches, please do not add confidentiality or non-disclosure
105notices to the patches themselves.  These notices conflict with the LLVM
106licensing terms and may result in your contribution being excluded.
107
108.. _github-email-address:
109
110Email Addresses
111---------------
112
113The LLVM project uses email to communicate to contributors outside of the
114GitHub platform about their past contributions. Primarily, our buildbot
115infrastructure uses emails to contact contributors about build and test
116failures.
117
118Therefore, the LLVM community requires contributors to have a public
119email address associated with their GitHub commits, so please ensure that "Keep
120my email addresses private" is disabled in your
121`account settings <https://github.com/settings/emails>`_.
122
123.. _code review:
124
125Code Reviews
126------------
127
128LLVM has a code-review policy. Code review is one way to increase the quality of
129software. Please see :doc:`CodeReview` for more information on LLVM's code-review
130process.
131
132.. _breaking:
133
134Making Potentially Breaking Changes
135-----------------------------------
136
137Please help notify users and vendors of potential disruptions when upgrading to
138a newer version of a tool. For example, deprecating a feature that is expected
139to be removed in the future, removing an already-deprecated feature, upgrading a
140diagnostic from a warning to an error, switching important default behavior, or
141any other potentially disruptive situation thought to be worth raising
142awareness of. For such changes, the following should be done:
143
144.. warning::
145
146  Phabricator is deprecated and is available in read-only mode,
147  for new code contributions use :ref:`GitHub Pull Requests <github-reviews>`.
148  This section contains old information that needs to be updated.
149
150* When performing the code review for the change, please add any applicable
151  "vendors" group to the review for their awareness. The purpose of these
152  groups is to give vendors early notice that potentially disruptive changes
153  are being considered but have not yet been accepted. Vendors can give early
154  testing feedback on the changes to alert us to unacceptable breakages. The
155  current list of vendor groups is:
156
157  * `Clang vendors <https://reviews.llvm.org/project/members/113/>`_
158  * `libc++ vendors <https://reviews.llvm.org/project/members/109/>`_
159
160  People interested in joining the vendors group can do so by clicking the
161  "Join Project" link on the vendor's "Members" page in Phabricator.
162
163* When committing the change to the repository, add appropriate information
164  about the potentially breaking changes to the ``Potentially Breaking Changes``
165  section of the project's release notes. The release note should have
166  information about what the change is, what is potentially disruptive about
167  it, as well as any code examples, links, and motivation that is appropriate
168  to share with users. This helps users to learn about potential issues with
169  upgrading to that release.
170
171* After the change has been committed to the repository, the potentially
172  disruptive changes described in the release notes should be posted to the
173  `Announcements <https://discourse.llvm.org/c/announce/>`_ channel on
174  Discourse. The post should be tagged with the ``potentially-breaking`` label
175  and a label specific to the project (such as ``clang``, ``llvm``, etc). This
176  is another mechanism by which we can give pre-release notice to users about
177  potentially disruptive changes. It is a lower-traffic alternative to the
178  joining "vendors" group. To automatically be notified of new announcements
179  with the ``potentially-breaking`` label, go to your user preferences page in
180  Discourse, and add the label to one of the watch categories under
181  ``Notifications->Tags``.
182
183.. _maintainers:
184
185Maintainers
186-----------
187
188The LLVM Project aims to evolve features quickly while continually being in a
189release-ready state. In order to accomplish this, the project needs volunteers
190willing to do the less glamorous work to ensure we produce robust, high-quality
191products.
192
193Maintainers are those volunteers; they are regular contributors who volunteer
194to take on additional community responsibilities beyond code contributions.
195Community members can find active and inactive maintainers for a project in the
196``Maintainers.rst`` file at the root directory of the individual project.
197
198Maintainers are volunteering to take on the following shared responsibilities
199within an area of a project:
200
201    * ensure that commits receive high-quality review, either by the maintainer
202      or by someone else,
203    * help to confirm and comment on issues,
204    * mediate code review disagreements through collaboration with other
205      maintainers (and other reviewers) to come to a consensus on how best to
206      proceed with disputed changes,
207    * actively engage with relevant RFCs,
208    * aid release managers with backporting and other release-related
209      activities,
210    * be a point of contact for contributors who need help (answering questions
211      on Discord/Discourse or holding office hours).
212
213Each top-level project in the monorepo will specify one or more
214lead maintainers who are responsible for ensuring community needs are
215met for that project. This role is like any other maintainer role,
216except the responsibilities span the project rather than a limited area
217within the project. If you cannot reach a maintainer or don't know which
218maintainer to reach out to, a lead maintainer is always a good choice
219to reach out to. If a project has no active lead maintainers, it may be a
220reasonable candidate for removal from the monorepo. A discussion should be
221started on Discourse to find a new, active lead maintainer or whether the
222project should be discontinued.
223
224All contributors with commit access to the LLVM Project are eligible to be a
225maintainer. However, we are looking for people who can commit to:
226
227    * engaging in their responsibilities the majority of the days in a month,
228    * ensuring that they, and the community members they interact with, abide by
229      the LLVM Community Code of Conduct, and
230    * performing these duties for at least three months.
231
232We recognize that priorities shift, job changes happen, burnout is real,
233extended vacations are a blessing, and people's lives are generally complex.
234Therefore, we want as little friction as possible for someone to become a
235maintainer or to step down as a maintainer.
236
237*To become a new maintainer*, you can volunteer yourself by posting a PR which
238adds yourself to the area(s) you are volunteering for. Alternatively, an
239existing maintainer can nominate you by posting a PR, but the nominee must
240explicitly accept the PR so that it's clear they agree to volunteer within the
241proposed area(s). The PR will be accepted so long as at least one maintainer in
242the same project vouches for their ability to perform the responsibilities and
243there are no explicit objections raised by the community.
244
245*To step down as a maintainer*, you can move your name to the "inactive
246maintainers" section of the ``Maintainers.rst`` file for the project, or remove
247your name entirely; no PR review is necessary. Additionally, any maintainer who
248has not been actively performing their responsibilities over an extended period
249of time can be moved to the "inactive maintainers" section by another active
250maintainer within that project with agreement from one other active maintainer
251within that project. If there is only one active maintainer for a project,
252please post on Discourse to solicit wider community feedback about the removal
253and future direction for the project. However, please discuss the situation
254with the inactive maintainer before such removal to avoid accidental
255miscommunications. If the inactive maintainer is unreachable, no discussion
256with them is required. Stepping down or being removed as a maintainer is normal
257and does not prevent someone from resuming their activities as a maintainer in
258the future.
259
260*To resume activities as a maintainer*, you can post a PR moving your name from
261the "inactive maintainers" section of the ``Maintainers.rst`` file to the
262active maintainers list. Because the volunteer was already previously accepted,
263they will be re-accepted so long as at least one maintainer in the same project
264approves the PR and there are no explicit objections raised by the community.
265
266.. _include a testcase:
267
268Test Cases
269----------
270
271Developers are required to create test cases for any bugs fixed and any new
272features added.  Some tips for getting your testcase approved:
273
274* All feature and regression test cases are added to the ``llvm/test``
275  directory. The appropriate sub-directory should be selected (see the
276  :doc:`Testing Guide <TestingGuide>` for details).
277
278* Test cases should be written in :doc:`LLVM assembly language <LangRef>`.
279
280* Test cases, especially for regressions, should be reduced as much as possible,
281  by :doc:`bugpoint <Bugpoint>` or manually. It is unacceptable to place an
282  entire failing program into ``llvm/test`` as this creates a *time-to-test*
283  burden on all developers. Please keep them short.
284
285* Avoid adding links to resources that are not available to the entire
286  community, such as links to private bug trackers, internal corporate
287  documentation, etc. Instead, add sufficient comments to the test to provide
288  the context behind such links.
289
290Note that llvm/test and clang/test are designed for regression and small feature
291tests only. More extensive test cases (e.g., entire applications, benchmarks,
292etc) should be added to the ``llvm-test`` test suite.  The llvm-test suite is
293for coverage (correctness, performance, etc) testing, not feature or regression
294testing.
295
296Release Notes
297-------------
298
299Many projects in LLVM communicate important changes to users through release
300notes, typically found in ``docs/ReleaseNotes.rst`` for the project. Changes to
301a project that are user-facing, or that users may wish to know about, should be
302added to the project's release notes at the author's or code reviewer's
303discretion, preferably as part of the commit landing the changes. Examples of
304changes that would typically warrant adding a release note (this list is not
305exhaustive):
306
307* Adding, removing, or modifying command-line options.
308* Adding, removing, or regrouping a diagnostic.
309* Fixing a bug that potentially has significant user-facing impact (please link
310  to the issue fixed in the bug database).
311* Adding or removing optimizations that have widespread impact or enables new
312  programming paradigms.
313* Modifying a C stable API.
314* Notifying users about a potentially disruptive change expected to be made in
315  a future release, such as removal of a deprecated feature. In this case, the
316  release note should be added to a ``Potentially Breaking Changes`` section of
317  the notes with sufficient information and examples to demonstrate the
318  potential disruption. Additionally, any new entries to this section should be
319  announced in the `Announcements <https://discourse.llvm.org/c/announce/>`_
320  channel on Discourse. See :ref:`breaking` for more details.
321
322Code reviewers are encouraged to request a release note if they think one is
323warranted when performing a code review.
324
325Quality
326-------
327
328The minimum quality standards that any change must satisfy before being
329committed to the main development branch are:
330
331#. Code must adhere to the `LLVM Coding Standards <CodingStandards.html>`_.
332
333#. Code must compile cleanly (no errors, no warnings) on at least one platform.
334
335#. Bug fixes and new features should `include a testcase`_ so we know if the
336   fix/feature ever regresses in the future.
337
338#. Code must pass the ``llvm/test`` test suite.
339
340#. The code must not cause regressions on a reasonable subset of llvm-test,
341   where "reasonable" depends on the contributor's judgement and the scope of
342   the change (more invasive changes require more testing). A reasonable subset
343   might be something like "``llvm-test/MultiSource/Benchmarks``".
344
345#. Ensure that links in source code and test files point to publicly available
346   resources and are used primarily to add additional information rather than
347   to supply critical context. The surrounding comments should be sufficient
348   to provide the context behind such links.
349
350Additionally, the committer is responsible for addressing any problems found in
351the future that the change is responsible for.  For example:
352
353* The code should compile cleanly on all supported platforms.
354
355* The changes should not cause any correctness regressions in the ``llvm-test``
356  suite and must not cause any major performance regressions.
357
358* The change set should not cause performance or correctness regressions for the
359  LLVM tools.
360
361* The changes should not cause performance or correctness regressions in code
362  compiled by LLVM on all applicable targets.
363
364* You are expected to address any `GitHub Issues <https://github.com/llvm/llvm-project/issues>`_ that
365  result from your change.
366
367We prefer for this to be handled before submission but understand that it isn't
368possible to test all of this for every submission.  Our build bots and nightly
369testing infrastructure normally finds these problems.  A good rule of thumb is
370to check the nightly testers for regressions the day after your change.  Build
371bots will directly email you if a group of commits that included yours caused a
372failure.  You are expected to check the build bot messages to see if they are
373your fault and, if so, fix the breakage.
374
375Commits that violate these quality standards (e.g. are very broken) may be
376reverted. This is necessary when the change blocks other developers from making
377progress. The developer is welcome to re-commit the change after the problem has
378been fixed.
379
380.. _commit messages:
381
382Commit messages
383---------------
384
385Although we don't enforce the format of commit messages, we prefer that
386you follow these guidelines to help review, search in logs, email formatting
387and so on. These guidelines are very similar to rules used by other open source
388projects.
389
390Most importantly, the contents of the message should be carefully written to
391convey the rationale of the change (without delving too much in detail). It
392also should avoid being vague or overly specific. For example, "bits were not
393set right" will leave the reviewer wondering about which bits, and why they
394weren't right, while "Correctly set overflow bits in TargetInfo" conveys almost
395all there is to the change.
396
397Below are some guidelines about the format of the message itself:
398
399* Separate the commit message into title and body separated by a blank line.
400
401* If you're not the original author, ensure the 'Author' property of the commit is
402  set to the original author and the 'Committer' property is set to yourself.
403  You can use a command similar to
404  ``git commit --amend --author="John Doe <jdoe@llvm.org>"`` to correct the
405  author property if it is incorrect. See `Attribution of Changes`_ for more
406  information including the method we used for attribution before the project
407  migrated to git.
408
409  In the rare situation where there are multiple authors, please use the `git
410  tag 'Co-authored-by:' to list the additional authors
411  <https://github.blog/2018-01-29-commit-together-with-co-authors/>`_.
412
413* The title should be concise. Because all commits are emailed to the list with
414  the first line as the subject, long titles are frowned upon.  Short titles
415  also look better in `git log`.
416
417* When the changes are restricted to a specific part of the code (e.g. a
418  back-end or optimization pass), it is customary to add a tag to the
419  beginning of the line in square brackets.  For example, "[SCEV] ..."
420  or "[OpenMP] ...". This helps email filters and searches for post-commit
421  reviews.
422
423* The body, if it exists, should be separated from the title by an empty line.
424
425* The body should be concise, but explanatory, including a complete
426  reasoning.  Unless it is required to understand the change, examples,
427  code snippets and gory details should be left to bug comments, web
428  review or the mailing list.
429
430* Text formatting and spelling should follow the same rules as documentation
431  and in-code comments, ex. capitalization, full stop, etc.
432
433* If the commit is a bug fix on top of another recently committed patch, or a
434  revert or reapply of a patch, include the git commit hash of the prior
435  related commit. This could be as simple as "Revert commit NNNN because it
436  caused PR#".
437
438* If the patch has been reviewed, add a link to its review page, as shown
439  `here <https://www.llvm.org/docs/Phabricator.html#committing-a-change>`__.
440  If the patch fixes a bug in GitHub Issues, we encourage adding a reference to
441  the issue being closed, as described
442  `here <https://llvm.org/docs/BugLifeCycle.html#resolving-closing-bugs>`__.
443
444* It is also acceptable to add other metadata to the commit message to automate
445  processes, including for downstream consumers. This metadata can include
446  links to resources that are not available to the entire community. However,
447  such links and/or metadata should not be used in place of making the commit
448  message self-explanatory. Note that such non-public links should not be
449  included in the submitted code.
450
451For minor violations of these recommendations, the community normally favors
452reminding the contributor of this policy over reverting. Minor corrections and
453omissions can be handled by sending a reply to the commits mailing list.
454
455.. _revert_policy:
456
457Patch reversion policy
458----------------------
459
460As a community, we strongly value having the tip of tree in a good state while
461allowing rapid iterative development.  As such, we tend to make much heavier
462use of reverts to keep the tree healthy than some other open source projects,
463and our norms are a bit different.
464
465How should you respond if someone reverted your change?
466
467* Remember, it is normal and healthy to have patches reverted.  Having a patch
468  reverted does not necessarily mean you did anything wrong.
469* We encourage explicitly thanking the person who reverted the patch for doing
470  the task on your behalf.
471* If you need more information to address the problem, please follow up in the
472  original commit thread with the reverting patch author.
473
474When should you revert your own change?
475
476* Any time you learn of a serious problem with a change, you should revert it.
477  We strongly encourage "revert to green" as opposed to "fixing forward".  We
478  encourage reverting first, investigating offline, and then reapplying the
479  fixed patch - possibly after another round of review if warranted.
480* If you break a buildbot in a way which can't be quickly fixed, please revert.
481* If a test case that demonstrates a problem is reported in the commit thread,
482  please revert and investigate offline.
483* If you receive substantial :ref:`post-commit review <post_commit_review>`
484  feedback, please revert and address said feedback before recommitting.
485  (Possibly after another round of review.)
486* If you are asked to revert by another contributor, please revert and discuss
487  the merits of the request offline (unless doing so would further destabilize
488  tip of tree).
489
490When should you revert someone else's change?
491
492* In general, if the author themselves would revert the change per these
493  guidelines, we encourage other contributors to do so as a courtesy to the
494  author.  This is one of the major cases where our norms differ from others;
495  we generally consider reverting a normal part of development.  We don't
496  expect contributors to be always available, and the assurance that a
497  problematic patch will be reverted and we can return to it at our next
498  opportunity enables this.
499
500What are the expectations around a revert?
501
502* Use your best judgment. If you're uncertain, please start an email on
503  the commit thread asking for assistance.  We aren't trying to enumerate
504  every case, but rather give a set of guidelines.
505* You should be sure that reverting the change improves the stability of tip
506  of tree.  Sometimes reverting one change in a series can worsen things
507  instead of improving them.  We expect reasonable judgment to ensure that
508  the proper patch or set of patches is being reverted.
509* The commit message for the reverting commit should explain why patch
510  is being reverted.
511* It is customary to respond to the original commit email mentioning the
512  revert.  This serves as both a notice to the original author that their
513  patch was reverted, and helps others following llvm-commits track context.
514* Ideally, you should have a publicly reproducible test case ready to share.
515  Where possible, we encourage sharing of test cases in commit threads, or
516  in PRs.  We encourage the reverter to minimize the test case and to prune
517  dependencies where practical.  This even applies when reverting your own
518  patch; documenting the reasons for others who might be following along
519  is critical.
520* It is not considered reasonable to revert without at least the promise to
521  provide a means for the patch author to debug the root issue.  If a situation
522  arises where a public reproducer can not be shared for some reason (e.g.
523  requires hardware patch author doesn't have access to, sharp regression in
524  compile time of internal workload, etc.), the reverter is expected to be
525  proactive about working with the patch author to debug and test candidate
526  patches.
527* Reverts should be reasonably timely.  A change submitted two hours ago
528  can be reverted without prior discussion.  A change submitted two years ago
529  should not be.  Where exactly the transition point is is hard to say, but
530  it's probably in the handful of days in tree territory.  If you are unsure,
531  we encourage you to reply to the commit thread, give the author a bit to
532  respond, and then proceed with the revert if the author doesn't seem to be
533  actively responding.
534* When re-applying a reverted patch, the commit message should be updated to
535  indicate the problem that was addressed and how it was addressed.
536
537.. _obtaining_commit_access:
538
539Obtaining Commit Access
540-----------------------
541
542We grant commit access to contributors that can provide a valid justification.
543If you would like commit access, please use this `link <https://github.com/llvm/llvm-project/issues/new?title=Request%20Commit%20Access%20For%20%3Cuser%3E&body=%23%23%23%20Why%20Are%20you%20requesting%20commit%20access%20?>`_ to file
544an issue and request commit access. Replace the <user> string in the title
545with your github username, and explain why you are requesting commit access in
546the issue description. If approved, a GitHub invitation will be sent to your
547GitHub account. In case you don't get notification from GitHub, go to
548`Invitation Link <https://github.com/orgs/llvm/invitation>`_ directly. Once
549you accept the invitation, you'll get commit access.
550
551Prior to obtaining commit access, it is common practice to request that
552someone with commit access commits on your behalf. When doing so, please
553provide the name and email address you would like to use in the Author
554property of the commit.
555
556For external tracking purposes, committed changes are automatically reflected
557on a commits mailing list soon after the commit lands (e.g. llvm-commits_).
558Note that these mailing lists are moderated, and it is not unusual for a large
559commit to require a moderator to approve the email, so do not be concerned if a
560commit does not immediately appear in the archives.
561
562If you have recently been granted commit access, these policies apply:
563
564#. You are granted *commit-after-approval* to all parts of LLVM. For
565   information on how to get approval for a patch, please see :doc:`CodeReview`.
566   When approved, you may commit it yourself.
567
568#. You are allowed to commit patches without approval which you think are
569   obvious. This is clearly a subjective decision --- we simply expect you to
570   use good judgement.  Examples include: fixing build breakage, reverting
571   obviously broken patches, documentation/comment changes, any other minor
572   changes. Avoid committing formatting- or whitespace-only changes outside of
573   code you plan to make subsequent changes to. Also, try to separate
574   formatting or whitespace changes from functional changes, either by
575   correcting the format first (ideally) or afterward. Such changes should be
576   highly localized and the commit message should clearly state that the commit
577   is not intended to change functionality, usually by stating it is
578   :ref:`NFC <nfc>`.
579
580#. You are allowed to commit patches without approval to those portions of LLVM
581   that you have contributed or maintain (i.e., have been assigned
582   responsibility for), with the proviso that such commits must not break the
583   build.  This is a "trust but verify" policy, and commits of this nature are
584   reviewed after they are committed.
585
586#. Multiple violations of these policies or a single egregious violation may
587   cause commit access to be revoked.
588
589In any case, your changes are still subject to `code review`_ (either before or
590after they are committed, depending on the nature of the change).  You are
591encouraged to review other peoples' patches as well, but you aren't required
592to do so.
593
594.. _discuss the change/gather consensus:
595
596Making a Major Change
597---------------------
598
599When a developer begins a major new project with the aim of contributing it back
600to LLVM, they should inform the community with a post to the `LLVM Discourse forums`_, to the extent
601possible. The reason for this is to:
602
603#. keep the community informed about future changes to LLVM,
604
605#. avoid duplication of effort by preventing multiple parties working on the
606   same thing and not knowing about it, and
607
608#. ensure that any technical issues around the proposed work are discussed and
609   resolved before any significant work is done.
610
611The design of LLVM is carefully controlled to ensure that all the pieces fit
612together well and are as consistent as possible. If you plan to make a major
613change to the way LLVM works or want to add a major new extension, it is a good
614idea to get consensus with the development community before you start working on
615it.
616
617Once the design of the new feature is finalized, the work itself should be done
618as a series of `incremental changes`_, not as a long-term development branch.
619
620.. _incremental changes:
621
622Incremental Development
623-----------------------
624
625In the LLVM project, we do all significant changes as a series of incremental
626patches.  We have a strong dislike for huge changes or long-term development
627branches.  Long-term development branches have a number of drawbacks:
628
629#. Branches must have mainline merged into them periodically.  If the branch
630   development and mainline development occur in the same pieces of code,
631   resolving merge conflicts can take a lot of time.
632
633#. Other people in the community tend to ignore work on branches.
634
635#. Huge changes (produced when a branch is merged back onto mainline) are
636   extremely difficult to `code review`_.
637
638#. Branches are not routinely tested by our nightly tester infrastructure.
639
640#. Changes developed as monolithic large changes often don't work until the
641   entire set of changes is done.  Breaking it down into a set of smaller
642   changes increases the odds that any of the work will be committed to the main
643   repository.
644
645To address these problems, LLVM uses an incremental development style and we
646require contributors to follow this practice when making a large/invasive
647change.  Some tips:
648
649* Large/invasive changes usually have a number of secondary changes that are
650  required before the big change can be made (e.g. API cleanup, etc).  These
651  sorts of changes can often be done before the major change is done,
652  independently of that work.
653
654* The remaining inter-related work should be decomposed into unrelated sets of
655  changes if possible.  Once this is done, define the first increment and get
656  consensus on what the end goal of the change is.
657
658* Each change in the set can be stand alone (e.g. to fix a bug), or part of a
659  planned series of changes that works towards the development goal.
660
661* Each change should be kept as small as possible. This simplifies your work
662  (into a logical progression), simplifies code review and reduces the chance
663  that you will get negative feedback on the change. Small increments also
664  facilitate the maintenance of a high quality code base.
665
666* Often, an independent precursor to a big change is to add a new API and slowly
667  migrate clients to use the new API.  Each change to use the new API is often
668  "obvious" and can be committed without review.  Once the new API is in place
669  and used, it is much easier to replace the underlying implementation of the
670  API.  This implementation change is logically separate from the API
671  change.
672
673If you are interested in making a large change, and this scares you, please make
674sure to first `discuss the change/gather consensus`_ then ask about the best way
675to go about making the change.
676
677Attribution of Changes
678----------------------
679
680When contributors submit a patch to an LLVM project, other developers with
681commit access may commit it for the author once appropriate (based on the
682progression of code review, etc.). When doing so, it is important to retain
683correct attribution of contributions to their contributors. However, we do not
684want the source code to be littered with random attributions "this code written
685by J. Random Hacker" (this is noisy and distracting). In practice, the revision
686control system keeps a perfect history of who changed what, and the CREDITS.txt
687file describes higher-level contributions. If you commit a patch for someone
688else, please follow the attribution of changes in the simple manner as outlined
689by the `commit messages`_ section. Overall, please do not add contributor names
690to the source code.
691
692Also, don't commit patches authored by others unless they have submitted the
693patch to the project or you have been authorized to submit them on their behalf
694(you work together and your company authorized you to contribute the patches,
695etc.). The author should first submit them to the relevant project's commit
696list, development list, or LLVM bug tracker component. If someone sends you
697a patch privately, encourage them to submit it to the appropriate list first.
698
699Our previous version control system (subversion) did not distinguish between the
700author and the committer like git does. As such, older commits used a different
701attribution mechanism. The previous method was to include "Patch by John Doe."
702in a separate line of the commit message and there are automated processes that
703rely on this format.
704
705Bans
706----
707
708The goal of a ban is to protect people in the community from having to interact
709with people who are consistently not respecting the
710:ref:`LLVM Community Code of Conduct` in LLVM project spaces. Contributions of
711any variety (pull requests, issue reports, forum posts, etc.) require
712interacting with the community. Therefore, we do not accept any form of direct
713contribution from a banned individual.
714
715Indirect contributions are permissible only by someone taking full ownership of
716such a contribution and they are responsible for all related interactions with
717the community regarding that contribution.
718
719When in doubt how to act in a specific instance, please reach out to
720conduct@llvm.org for advice.
721
722
723.. _IR backwards compatibility:
724
725IR Backwards Compatibility
726--------------------------
727
728When the IR format has to be changed, keep in mind that we try to maintain some
729backwards compatibility. The rules are intended as a balance between convenience
730for llvm users and not imposing a big burden on llvm developers:
731
732* The textual format is not backwards compatible. We don't change it too often,
733  but there are no specific promises.
734
735* Additions and changes to the IR should be reflected in
736  ``test/Bitcode/compatibility.ll``.
737
738* The current LLVM version supports loading any bitcode since version 3.0.
739
740* After each X.Y release, ``compatibility.ll`` must be copied to
741  ``compatibility-X.Y.ll``. The corresponding bitcode file should be assembled
742  using the X.Y build and committed as ``compatibility-X.Y.ll.bc``.
743
744* Newer releases can ignore features from older releases, but they cannot
745  miscompile them. For example, if nsw is ever replaced with something else,
746  dropping it would be a valid way to upgrade the IR.
747
748* Debug metadata is special in that it is currently dropped during upgrades.
749
750* Non-debug metadata is defined to be safe to drop, so a valid way to upgrade
751  it is to drop it. That is not very user friendly and a bit more effort is
752  expected, but no promises are made.
753
754C API Changes
755-------------
756
757* Stability Guarantees: The C API is, in general, a "best effort" for stability.
758  This means that we make every attempt to keep the C API stable, but that
759  stability will be limited by the abstractness of the interface and the
760  stability of the C++ API that it wraps. In practice, this means that things
761  like "create debug info" or "create this type of instruction" are likely to be
762  less stable than "take this IR file and JIT it for my current machine".
763
764* Release stability: We won't break the C API on the release branch with patches
765  that go on that branch, with the exception that we will fix an unintentional
766  C API break that will keep the release consistent with both the previous and
767  next release.
768
769* Testing: Patches to the C API are expected to come with tests just like any
770  other patch.
771
772* Including new things into the API: If an LLVM subcomponent has a C API already
773  included, then expanding that C API is acceptable. Adding C API for
774  subcomponents that don't currently have one needs to be discussed on the
775  `LLVM Discourse forums`_ for design and maintainability feedback prior to implementation.
776
777* Documentation: Any changes to the C API are required to be documented in the
778  release notes so that it's clear to external users who do not follow the
779  project how the C API is changing and evolving.
780
781.. _toolchain:
782
783Updating Toolchain Requirements
784-------------------------------
785
786We intend to require newer toolchains as time goes by. This means LLVM's
787codebase can use newer versions of C++ as they get standardized. Requiring newer
788toolchains to build LLVM can be painful for those building LLVM; therefore, it
789will only be done through the following process:
790
791  * It is a general goal to support LLVM and GCC versions from the last 3 years
792    at a minimum. This time-based guideline is not strict: we may support much
793    older compilers, or decide to support fewer versions.
794
795  * An RFC is sent to the `LLVM Discourse forums`_
796
797    - Detail upsides of the version increase (e.g. which newer C++ language or
798      library features LLVM should use; avoid miscompiles in particular compiler
799      versions, etc).
800    - Detail downsides on important platforms (e.g. Ubuntu LTS status).
801
802  * Once the RFC reaches consensus, update the CMake toolchain version checks as
803    well as the :doc:`getting started<GettingStarted>` guide.  This provides a
804    softer transition path for developers compiling LLVM, because the
805    error can be turned into a warning using a CMake flag. This is an important
806    step: LLVM still doesn't have code which requires the new toolchains, but it
807    soon will. If you compile LLVM but don't read the forums, we should
808    tell you!
809
810  * Ensure that at least one LLVM release has had this soft-error. Not all
811    developers compile LLVM top-of-tree. These release-bound developers should
812    also be told about upcoming changes.
813
814  * Turn the soft-error into a hard-error after said LLVM release has branched.
815
816  * Update the :doc:`coding standards<CodingStandards>` to allow the new
817    features we've explicitly approved in the RFC.
818
819  * Start using the new features in LLVM's codebase.
820
821Here's a `sample RFC
822<https://discourse.llvm.org/t/rfc-migrating-past-c-11/50943>`_ and the
823`corresponding change <https://reviews.llvm.org/D57264>`_.
824
825.. _ci-usage:
826
827Working with the CI system
828--------------------------
829
830The main continuous integration (CI) tool for the LLVM project is the
831`LLVM Buildbot <https://lab.llvm.org/buildbot/>`_. It uses different *builders*
832to cover a wide variety of sub-projects and configurations. The builds are
833executed on different *workers*. Builders and workers are configured and
834provided by community members.
835
836The Buildbot tracks the commits on the main branch and the release branches.
837This means that patches are built and tested after they are merged to the these
838branches (aka post-merge testing). This also means it's okay to break the build
839occasionally, as it's unreasonable to expect contributors to build and test
840their patch with every possible configuration.
841
842*If your commit broke the build:*
843
844* Fix the build as soon as possible as this might block other contributors or
845  downstream users.
846* If you need more time to analyze and fix the bug, please revert your change to
847  unblock others.
848
849*If someone else broke the build and this blocks your work*
850
851* Comment on the code review in `GitHub <https://github.com/llvm/llvm-project/pulls>`_
852  (if available) or email the author, explain the problem and how this impacts
853  you. Add a link to the broken build and the error message so folks can
854  understand the problem.
855* Revert the commit if this blocks your work, see revert_policy_ .
856
857*If a build/worker is permanently broken*
858
859* 1st step: contact the owner of the worker. You can find the name and contact
860  information for the *Admin* of worker on the page of the build in the
861  *Worker* tab:
862
863  .. image:: buildbot_worker_contact.png
864
865* 2nd step: If the owner does not respond or fix the worker, please escalate
866  to Galina Kostanova, the maintainer of the BuildBot master.
867* 3rd step: If Galina could not help you, please escalate to the
868  `Infrastructure Working Group <mailto:iwg@llvm.org>`_.
869
870.. _new-llvm-components:
871
872Introducing New Components into LLVM
873====================================
874
875The LLVM community is a vibrant and exciting place to be, and we look to be
876inclusive of new projects and foster new communities, and increase
877collaboration across industry and academia.
878
879That said, we need to strike a balance between being inclusive of new ideas and
880people and the cost of ongoing maintenance that new code requires.  As such, we
881have a general :doc:`support policy<SupportPolicy>` for introducing major new
882components into the LLVM world, depending on the degree of detail and
883responsibility required. *Core* projects need a higher degree of scrutiny
884than *peripheral* projects, and the latter may have additional differences.
885
886However, this is really only intended to cover common cases
887that we have seen arise: different situations are different, and we are open
888to discussing unusual cases as well - just start an RFC thread on the
889`LLVM Discourse forums`_.
890
891Adding a New Target
892-------------------
893
894LLVM is very receptive to new targets, even experimental ones, but a number of
895problems can appear when adding new large portions of code, and back-ends are
896normally added in bulk. New targets need the same level of support as other
897*core* parts of the compiler, so they are covered in the *core tier* of our
898:doc:`support policy<SupportPolicy>`.
899
900We have found that landing large pieces of new code and then trying to fix
901emergent problems in-tree is problematic for a variety of reasons. For these
902reasons, new targets are *always* added as *experimental* until they can be
903proven stable, and later moved to non-experimental.
904
905The differences between both classes are:
906
907* Experimental targets are not built by default (they need to be explicitly
908  enabled at CMake time).
909
910* Test failures, bugs, and build breakages that only appear when the
911  experimental target is enabled, caused by changes unrelated to the target, are
912  the responsibility of the community behind the target to fix.
913
914The basic rules for a back-end to be upstreamed in **experimental** mode are:
915
916* Every target must have at least one :ref:`maintainer<maintainers>`. The
917  `Maintainers.rst` file has to be updated as part of the first merge. These
918  maintainers make sure that changes to the target get reviewed and steers the
919  overall effort.
920
921* There must be an active community behind the target. This community
922  will help maintain the target by providing buildbots, fixing
923  bugs, answering the LLVM community's questions and making sure the new
924  target doesn't break any of the other targets, or generic code. This
925  behavior is expected to continue throughout the lifetime of the
926  target's code.
927
928* The code must be free of contentious issues, for example, large
929  changes in how the IR behaves or should be formed by the front-ends,
930  unless agreed by the majority of the community via refactoring of the
931  (:doc:`IR standard<LangRef>`) **before** the merge of the new target changes,
932  following the :ref:`IR backwards compatibility`.
933
934* The code conforms to all of the policies laid out in this developer policy
935  document, including license, patent, and coding standards.
936
937* The target should have either reasonable documentation on how it
938  works (ISA, ABI, etc.) or a publicly available simulator/hardware
939  (either free or cheap enough) - preferably both.  This allows
940  developers to validate assumptions, understand constraints and review code
941  that can affect the target.
942
943In addition, the rules for a back-end to be promoted to **official** are:
944
945* The target must have addressed every other minimum requirement and
946  have been stable in tree for at least 3 months. This cool down
947  period is to make sure that the back-end and the target community can
948  endure continuous upstream development for the foreseeable future.
949
950* The target's code must have been completely adapted to this policy
951  as well as the :doc:`coding standards<CodingStandards>`. Any exceptions that
952  were made to move into experimental mode must have been fixed **before**
953  becoming official.
954
955* The test coverage needs to be broad and well written (small tests,
956  well documented). The build target ``check-all`` must pass with the
957  new target built, and where applicable, the ``test-suite`` must also
958  pass without errors, in at least one configuration (publicly
959  demonstrated, for example, via buildbots).
960
961* Public buildbots need to be created and actively maintained, unless
962  the target requires no additional buildbots (ex. ``check-all`` covers
963  all tests). The more relevant and public the new target's CI infrastructure
964  is, the more the LLVM community will embrace it.
965
966To **continue** as a supported and official target:
967
968* The maintainer(s) must continue following these rules throughout the lifetime
969  of the target. Continuous violations of aforementioned rules and policies
970  could lead to complete removal of the target from the code base.
971
972* Degradation in support, documentation or test coverage will make the target as
973  nuisance to other targets and be considered a candidate for deprecation and
974  ultimately removed.
975
976In essence, these rules are necessary for targets to gain and retain their
977status, but also markers to define bit-rot, and will be used to clean up the
978tree from unmaintained targets.
979
980Those wishing to add a new target to LLVM must follow the procedure below:
981
9821. Read this section and make sure your target follows all requirements. For
983   minor issues, your community will be responsible for making all necessary
984   adjustments soon after the initial merge.
9852. Send a request for comment (RFC) to the `LLVM Discourse forums`_ describing
986   your target and how it follows all the requirements and what work has been
987   done and will need to be done to accommodate the official target requirements.
988   Make sure to expose any and all controversial issues, changes needed in the
989   base code, table gen, etc.
9903. Once the response is positive, the LLVM community can start reviewing the
991   actual patches (but they can be prepared before, to support the RFC). Create
992   a sequence of N patches, numbered '1/N' to 'N/N' (make sure N is an actual
993   number, not the letter 'N'), that completes the basic structure of the target.
9944. The initial patch should add documentation, maintainers, and triple support in
995   clang and LLVM. The following patches add TableGen infrastructure to describe
996   the target and lower instructions to assembly. The final patch must show that
997   the target can lower correctly with extensive LIT tests (IR to MIR, MIR to
998   ASM, etc).
9995. Some patches may be approved before others, but only after *all* patches are
1000   approved that the whole set can be merged in one go. This is to guarantee
1001   that all changes are good as a single block.
10026. After the initial merge, the target community can stop numbering patches and
1003   start working asynchronously on the target to complete support. They should
1004   still seek review from those who helped them in the initial phase, to make
1005   sure the progress is still consistent.
10067. Once all official requirements have been fulfilled (as above), the maintainers
1007   should request the target to be enabled by default by sending another RFC to
1008   the `LLVM Discourse forums`_.
1009
1010Adding an Established Project To the LLVM Monorepo
1011--------------------------------------------------
1012
1013The `LLVM monorepo <https://github.com/llvm/llvm-project>`_ is the centerpoint
1014of development in the LLVM world, and has all of the primary LLVM components,
1015including the LLVM optimizer and code generators, Clang, LLDB, etc.  `Monorepos
1016in general <https://en.wikipedia.org/wiki/Monorepo>`_ are great because they
1017allow atomic commits to the project, simplify CI, and make it easier for
1018subcommunities to collaborate.
1019
1020Like new targets, most projects already in the monorepo are considered to be in
1021the *core tier* of our :doc:`support policy<SupportPolicy>`. The burden to add
1022things to the LLVM monorepo needs to be very high - code that is added to this
1023repository is checked out by everyone in the community.  As such, we hold
1024components to a high bar similar to "official targets", they:
1025
1026 * Must be generally aligned with the mission of the LLVM project to advance
1027   compilers, languages, tools, runtimes, etc.
1028 * Must conform to all of the policies laid out in this developer policy
1029   document, including license, patent, coding standards, and code of conduct.
1030 * Must have an active community that maintains the code, including established
1031   maintainers.
1032 * Should have reasonable documentation about how it works, including a high
1033   quality README file.
1034 * Should have CI to catch breakage within the project itself or due to
1035   underlying LLVM dependencies.
1036 * Should have code free of issues the community finds contentious, or be on a
1037   clear path to resolving them.
1038 * Must be proposed through the LLVM RFC process, and have its addition approved
1039   by the LLVM community - this ultimately mediates the resolution of the
1040   "should" concerns above.
1041
1042If you have a project that you think would make sense to add to the LLVM
1043monorepo, please start an RFC topic on the `LLVM Discourse forums`_ to kick off
1044the discussion.  This process can take some time and iteration - please don’t
1045be discouraged or intimidated by that!
1046
1047If you have an earlier stage project that you think is aligned with LLVM, please
1048see the "Incubating New Projects" section.
1049
1050Incubating New Projects
1051-----------------------
1052
1053The burden to add a new project to the LLVM monorepo is intentionally very high,
1054but that can have a chilling effect on new and innovative projects.  To help
1055foster these sorts of projects, LLVM supports an "incubator" process that is
1056much easier to get started with.  It provides space for potentially valuable,
1057new top-level and sub-projects to reach a critical mass before they have enough
1058code to prove their utility and grow a community.  This also allows
1059collaboration between teams that already have permissions to make contributions
1060to projects under the LLVM umbrella.
1061
1062Projects which can be considered for the LLVM incubator meet the following
1063criteria:
1064
1065 * Must be generally aligned with the mission of the LLVM project to advance
1066   compilers, languages, tools, runtimes, etc.
1067 * Must conform to the license, patent, and code of conduct policies laid out
1068   in this developer policy document.
1069 * Must have a documented charter and development plan, e.g. in the form of a
1070   README file, mission statement, and/or manifesto.
1071 * Should conform to coding standards, incremental development process, and
1072   other expectations.
1073 * Should have a sense of the community that it hopes to eventually foster, and
1074   there should be interest from members with different affiliations /
1075   organizations.
1076 * Should have a feasible path to eventually graduate as a dedicated top-level
1077   or sub-project within the `LLVM monorepo
1078   <https://github.com/llvm/llvm-project>`_.
1079 * Should include a notice (e.g. in the project README or web page) that the
1080   project is in ‘incubation status’ and is not included in LLVM releases (see
1081   suggested wording below).
1082 * Must be proposed through the LLVM RFC process, and have its addition
1083   approved by the LLVM community - this ultimately mediates the resolution of
1084   the "should" concerns above.
1085
1086That said, the project need not have any code to get started, and need not have
1087an established community at all!  Furthermore, incubating projects may pass
1088through transient states that violate the "Should" guidelines above, or would
1089otherwise make them unsuitable for direct inclusion in the monorepo (e.g.
1090dependencies that have not yet been factored appropriately, leveraging
1091experimental components or APIs that are not yet upstream, etc).
1092
1093When approved, the llvm-admin group can grant the new project:
1094 * A new repository in the LLVM Github Organization - but not the LLVM monorepo.
1095 * New mailing list, discourse forum, and/or discord chat hosted with other LLVM
1096   forums.
1097 * Other infrastructure integration can be discussed on a case-by-case basis.
1098
1099Graduation to the mono-repo would follow existing processes and standards for
1100becoming a first-class part of the monorepo.  Similarly, an incubating project
1101may be eventually retired, but no process has been established for that yet.  If
1102and when this comes up, please start an RFC discussion on the `LLVM Discourse forums`_.
1103
1104This process is very new - please expect the details to change, it is always
1105safe to ask on the `LLVM Discourse forums`_ about this.
1106
1107Suggested disclaimer for the project README and the main project web page:
1108
1109::
1110
1111   This project is participating in the LLVM Incubator process: as such, it is
1112   not part of any official LLVM release.  While incubation status is not
1113   necessarily a reflection of the completeness or stability of the code, it
1114   does indicate that the project is not yet endorsed as a component of LLVM.
1115
1116.. _copyright-license-patents:
1117
1118Copyright, License, and Patents
1119===============================
1120
1121.. note::
1122
1123   This section deals with legal matters but does not provide legal advice.  We
1124   are not lawyers --- please seek legal counsel from a licensed attorney.
1125
1126This section addresses the issues of copyright, license and patents for the LLVM
1127project.  The copyright for the code is held by the contributors of
1128the code.  The code is licensed under permissive `open source licensing terms`_,
1129namely the Apache-2.0 with LLVM-exception license, which includes a copyright
1130and `patent license`_.  When you contribute code to the LLVM project, you
1131license it under these terms.
1132
1133In certain circumstances, code licensed under other licenses can be added
1134to the codebase.  However, this may only be done with approval of the LLVM
1135Foundation Board of Directors, and contributors should plan for the approval
1136process to take at least 4-6 weeks.  If you would like to contribute code
1137under a different license, please create a pull request with the code
1138you want to contribute and email board@llvm.org requesting a review.
1139
1140If you have questions or comments about these topics, please ask on the
1141`LLVM Discourse forums`_.  However,
1142please realize that most compiler developers are not lawyers, and therefore you
1143will not be getting official legal advice.
1144
1145.. _LLVM Discourse forums: https://discourse.llvm.org
1146
1147Copyright
1148---------
1149
1150The LLVM project does not collect copyright assignments, which means that the
1151copyright for the code in the project is held by the respective contributors.
1152Because you (or your company)
1153retain ownership of the code you contribute, you know it may only be used under
1154the terms of the open source license you contributed it under: the license for
1155your contributions cannot be changed in the future without your approval.
1156
1157Because the LLVM project does not require copyright assignments, changing the
1158LLVM license requires tracking down the
1159contributors to LLVM and getting them to agree that a license change is
1160acceptable for their contributions.  We feel that a high burden for relicensing
1161is good for the project, because contributors do not have to fear that their
1162code will be used in a way with which they disagree.
1163
1164Embedded Copyright or 'Contributed by' Statements
1165^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1166
1167The LLVM project does not accept contributions that include in-source copyright
1168notices except where such notices are part of a larger external project being
1169added as a vendored dependency.
1170
1171LLVM source code lives for a long time and is edited by many people, the best
1172way to track contributions is through revision control history.
1173See the `Attribution of Changes`_ section for more information about attributing
1174changes to authors other than the committer.
1175
1176Relicensing
1177-----------
1178
1179The last paragraph notwithstanding, the LLVM Project is in the middle of a large
1180effort to change licenses, which aims to solve several problems:
1181
1182* The old licenses made it difficult to move code from (e.g.) the compiler to
1183  runtime libraries, because runtime libraries used a different license from the
1184  rest of the compiler.
1185* Some contributions were not submitted to LLVM due to concerns that
1186  the patent grant required by the project was overly broad.
1187* The patent grant was unique to the LLVM Project, not written by a lawyer, and
1188  was difficult to determine what protection was provided (if any).
1189
1190The scope of relicensing is all code that is considered part of the LLVM
1191project, including the main LLVM repository, runtime libraries (compiler_rt,
1192OpenMP, etc), Polly, and all other subprojects.  There are a few exceptions:
1193
1194* Code imported from other projects (e.g. Google Test, Autoconf, etc) will
1195  remain as it is.  This code isn't developed as part of the LLVM project, it
1196  is used by LLVM.
1197* Some subprojects are impractical or uninteresting to relicense (e.g. llvm-gcc
1198  and dragonegg). These will be split off from the LLVM project (e.g. to
1199  separate GitHub projects), allowing interested people to continue their
1200  development elsewhere.
1201
1202To relicense LLVM, we will be seeking approval from all of the copyright holders
1203of code in the repository, or potentially remove/rewrite code if we cannot.
1204This is a large
1205and challenging project which will take a significant amount of time to
1206complete.
1207
1208Starting on 2024-06-01 (first of June 2024), new contributions only need to
1209be covered by the new LLVM license, i.e. Apache-2.0 WITH LLVM-exception.
1210Before this date, the project required all contributions to be made under
1211both the new license and the legacy license.
1212
1213If you are a contributor to LLVM with contributions committed before 2019-01-19
1214and have not done so already, please do follow the instructions at
1215https://foundation.llvm.org/docs/relicensing/, under section "Individual
1216Relicensing Agreement" to relicense your contributions under the new license.
1217
1218
1219.. _open source licensing terms:
1220
1221New LLVM Project License Framework
1222----------------------------------
1223
1224Contributions to LLVM are licensed under the `Apache License, Version 2.0
1225<https://www.apache.org/licenses/LICENSE-2.0>`_, with two limited
1226exceptions intended to ensure that LLVM is very permissively licensed.
1227Collectively, the name of this license is "Apache 2.0 License with LLVM
1228exceptions".  The exceptions read:
1229
1230::
1231
1232   ---- LLVM Exceptions to the Apache 2.0 License ----
1233
1234   As an exception, if, as a result of your compiling your source code, portions
1235   of this Software are embedded into an Object form of such source code, you
1236   may redistribute such embedded portions in such Object form without complying
1237   with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
1238
1239   In addition, if you combine or link compiled forms of this Software with
1240   software that is licensed under the GPLv2 ("Combined Software") and if a
1241   court of competent jurisdiction determines that the patent provision (Section
1242   3), the indemnity provision (Section 9) or other Section of the License
1243   conflicts with the conditions of the GPLv2, you may retroactively and
1244   prospectively choose to deem waived or otherwise exclude such Section(s) of
1245   the License, but only in their entirety and only with respect to the Combined
1246   Software.
1247
1248
1249We intend to keep LLVM perpetually open source and available under a permissive
1250license - this fosters the widest adoption of LLVM by
1251**allowing commercial products to be derived from LLVM** with few restrictions
1252and without a requirement for making any derived works also open source.  In
1253particular, LLVM's license is not a "copyleft" license like the GPL.
1254
1255The "Apache 2.0 License with LLVM exceptions" allows you to:
1256
1257* freely download and use LLVM (in whole or in part) for personal, internal, or
1258  commercial purposes.
1259* include LLVM in packages or distributions you create.
1260* combine LLVM with code licensed under every other major open source
1261  license (including BSD, MIT, GPLv2, GPLv3...).
1262* make changes to LLVM code without being required to contribute it back
1263  to the project - contributions are appreciated though!
1264
1265However, it imposes these limitations on you:
1266
1267* You must retain the copyright notice if you redistribute LLVM: You cannot
1268  strip the copyright headers off or replace them with your own.
1269* Binaries that include LLVM must reproduce the copyright notice (e.g. in an
1270  included README file or in an "About" box), unless the LLVM code was added as
1271  a by-product of compilation.  For example, if an LLVM runtime library like
1272  compiler_rt or libc++ was automatically included into your application by the
1273  compiler, you do not need to attribute it.
1274* You can't use our names to promote your products (LLVM derived or not) -
1275  though you can make truthful statements about your use of the LLVM code,
1276  without implying our sponsorship.
1277* There's no warranty on LLVM at all.
1278
1279We want LLVM code to be widely used, and believe that this provides a model that
1280is great for contributors and users of the project.  For more information about
1281the Apache 2.0 License, please see the `Apache License FAQ
1282<http://www.apache.org/foundation/license-faq.html>`_, maintained by the
1283Apache Project.
1284
1285.. _patent license:
1286
1287Patents
1288-------
1289
1290Section 3 of the Apache 2.0 license is a patent grant under which
1291contributors of code to the project contribute the rights to use any of
1292their patents that would otherwise be infringed by that code contribution
1293(protecting uses of that code).  Further, the patent grant is revoked
1294from anyone who files a patent lawsuit about code in LLVM - this protects the
1295community by providing a "patent commons" for the code base and reducing the
1296odds of patent lawsuits in general.
1297
1298The license specifically scopes which patents are included with code
1299contributions.  To help explain this, the `Apache License FAQ
1300<http://www.apache.org/foundation/license-faq.html>`_ explains this scope using
1301some questions and answers, which we reproduce here for your convenience (for
1302reference, the "ASF" is the Apache Software Foundation, the guidance still
1303holds though)::
1304
1305   Q1: If I own a patent and contribute to a Work, and, at the time my
1306   contribution is included in that Work, none of my patent's claims are subject
1307   to Apache's Grant of Patent License, is there a way any of those claims would
1308   later become subject to the Grant of Patent License solely due to subsequent
1309   contributions by other parties who are not licensees of that patent.
1310
1311   A1: No.
1312
1313   Q2: If at any time after my contribution, I am able to license other patent
1314   claims that would have been subject to Apache's Grant of Patent License if
1315   they were licensable by me at the time of my contribution, do those other
1316   claims become subject to the Grant of Patent License?
1317
1318   A2: Yes.
1319
1320   Q3: If I own or control a licensable patent and contribute code to a specific
1321   Apache product, which of my patent claims are subject to Apache's Grant of
1322   Patent License?
1323
1324   A3:  The only patent claims that are licensed to the ASF are those you own or
1325   have the right to license that read on your contribution or on the
1326   combination of your contribution with the specific Apache product to which
1327   you contributed as it existed at the time of your contribution. No additional
1328   patent claims become licensed as a result of subsequent combinations of your
1329   contribution with any other software. Note, however, that licensable patent
1330   claims include those that you acquire in the future, as long as they read on
1331   your original contribution as made at the original time. Once a patent claim
1332   is subject to Apache's Grant of Patent License, it is licensed under the
1333   terms of that Grant to the ASF and to recipients of any software distributed
1334   by the ASF for any Apache software product whatsoever.
1335
1336.. _legacy:
1337
1338Legacy License Structure
1339------------------------
1340
1341.. note::
1342   The code base was previously licensed under the Terms described here.
1343   We are in the middle of relicensing to a new approach (described above).
1344   More than 99% of all contributions made to LLVM are covered by the Apache-2.0
1345   WITH LLVM-exception license. A small portion of LLVM code remains exclusively
1346   covered by the legacy license. Contributions after 2024-06-01 are covered
1347   exclusively by the new license._
1348
1349We intend to keep LLVM perpetually open source and to use a permissive open
1350source license.  The code in
1351LLVM is available under the `University of Illinois/NCSA Open Source License
1352<http://www.opensource.org/licenses/UoI-NCSA.php>`_, which boils down to
1353this:
1354
1355* You can freely distribute LLVM.
1356* You must retain the copyright notice if you redistribute LLVM.
1357* Binaries derived from LLVM must reproduce the copyright notice (e.g. in an
1358  included README file).
1359* You can't use our names to promote your LLVM derived products.
1360* There's no warranty on LLVM at all.
1361
1362We believe this fosters the widest adoption of LLVM because it **allows
1363commercial products to be derived from LLVM** with few restrictions and without
1364a requirement for making any derived works also open source (i.e. LLVM's
1365license is not a "copyleft" license like the GPL). We suggest that you read the
1366`License <http://www.opensource.org/licenses/UoI-NCSA.php>`_ if further
1367clarification is needed.
1368
1369In addition to the UIUC license, the runtime library components of LLVM
1370(**compiler_rt, libc++, and libclc**) are also licensed under the `MIT License
1371<http://www.opensource.org/licenses/mit-license.php>`_, which does not contain
1372the binary redistribution clause.  As a user of these runtime libraries, it
1373means that you can choose to use the code under either license (and thus don't
1374need the binary redistribution clause), and as a contributor to the code that
1375you agree that any contributions to these libraries be licensed under both
1376licenses.  We feel that this is important for runtime libraries, because they
1377are implicitly linked into applications and therefore should not subject those
1378applications to the binary redistribution clause. This also means that it is ok
1379to move code from (e.g.)  libc++ to the LLVM core without concern, but that code
1380cannot be moved from the LLVM core to libc++ without the copyright owner's
1381permission.
1382
1383.. _ai contributions:
1384
1385AI generated contributions
1386--------------------------
1387
1388Artificial intelligence systems raise many questions around copyright that have
1389yet to be answered. Our policy on AI tools is guided by our copyright policy:
1390Contributors are responsible for ensuring that they have the right to contribute
1391code under the terms of our license, typically meaning that either they, their
1392employer, or their collaborators hold the copyright. Using AI tools to
1393regenerate copyrighted material does not remove the copyright, and contributors
1394are responsible for ensuring that such material does not appear in their
1395contributions.
1396
1397As such, the LLVM policy is that contributors are permitted to use artificial
1398intelligence tools to produce contributions, provided that they have the right
1399to license that code under the project license. Contributions found to violate
1400this policy will be removed just like any other offending contribution.
1401
1402While the LLVM project has a liberal policy on AI tool use, contributors are
1403considered responsible for their contributions. We encourage contributors to
1404review all generated code before sending it for review to verify its
1405correctness and to understand it so that they can answer questions during code
1406review. Reviewing and maintaining generated code that the original contributor
1407does not understand is not a good use of limited project resources.
1408