[clang] [llvm] [docs] Add a section on AI-generated content to the developer policy (PR #91014)

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 10 16:14:14 PDT 2024


https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/91014

>From 88e4991013a05e26cece87d3989ad957a4e18e3d Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Wed, 4 Sep 2024 16:52:49 +0000
Subject: [PATCH 1/5] [clang] Fix FIXME in dynamic initializer emission, NFCI

This potentially affects platforms that support comdats other than ELF,
COFF, or wasm, but that is the intention of the FIXME, and if they don't
want this behavior, they probably shouldn't advertise comdat support.
---
 clang/lib/CodeGen/CGDeclCXX.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8dcb5f61006196..c44f38ef02a3f1 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -640,13 +640,13 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
       addUsedGlobal(COMDATKey);
     }
 
-    // If we used a COMDAT key for the global ctor, the init function can be
-    // discarded if the global ctor entry is discarded.
-    // FIXME: Do we need to restrict this to ELF and Wasm?
+    // If comdats are in use and supported, place the initializer function into
+    // the comdat group of the global. In the MS ABI, initializers are mangled
+    // and have their own comdat, so we don't include them in the group for
+    // consistency with MSVC.
     llvm::Comdat *C = Addr->getComdat();
-    if (COMDATKey && C &&
-        (getTarget().getTriple().isOSBinFormatELF() ||
-         getTarget().getTriple().isOSBinFormatWasm())) {
+    if (COMDATKey && C && getTriple().supportsCOMDAT() &&
+        !getTarget().getCXXABI().isMicrosoft()) {
       Fn->setComdat(C);
     }
   } else {

>From 33f2456d9d2c3130a07af988ff682d04e71deed0 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Fri, 3 May 2024 21:05:18 +0000
Subject: [PATCH 2/5] [docs] Add a section on AI-generated content to the
 developer policy

Governments around the world are starting to require labelling for
AI-generated content, and some LLVM stakeholders have asked if LLVM
contains AI-generated content. Defining a policy on the use of AI tools
allows us to answer that question affirmatively, one way of the other.

The policy proposed here allows the use of AI tools in LLVM
contributions, flowing from the idea that any contribution is fine
regardless of how it is made, as long as the contributor has the right
to license it under the project license.
---
 llvm/docs/DeveloperPolicy.rst | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/llvm/docs/DeveloperPolicy.rst b/llvm/docs/DeveloperPolicy.rst
index 49ec310b382f94..abb55cd670591c 100644
--- a/llvm/docs/DeveloperPolicy.rst
+++ b/llvm/docs/DeveloperPolicy.rst
@@ -1301,4 +1301,23 @@ to move code from (e.g.)  libc++ to the LLVM core without concern, but that code
 cannot be moved from the LLVM core to libc++ without the copyright owner's
 permission.
 
+.. _ai contributions:
+
+AI generated contributions
+--------------------------
+
+Artificial intelligence systems raise many questions around copyright that have
+yet to be answered. Our policy on AI tools is guided by our copyright policy:
+contributors are responsible for ensuring that they have the right to contribute
+code under the terms of our license, typically meaning that either they, their
+employer, or their collaborators hold the copyright. Using AI tools to
+regenerate copyrighted material does not remove the copyright, and contributors
+are responsible for ensuring that such material does not appear in their
+contributions.
+
+As such, the LLVM policy is that contributors are permitted to to use artificial
+intelligence tools to produce contributions, provided that they have the right
+to license that code under the project license. Contributions found to violate
+this policy will be removed just like any other offending contribution.
+
 .. _LLVM Discourse forums: https://discourse.llvm.org

>From 3a21994b9c6e78a24f918174cb3e8fe6c18dd00c Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Mon, 6 May 2024 23:06:09 +0000
Subject: [PATCH 3/5] Add FAQ entry

---
 llvm/docs/FAQ.rst | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/docs/FAQ.rst b/llvm/docs/FAQ.rst
index 229ac99f703c19..aa20de47a69980 100644
--- a/llvm/docs/FAQ.rst
+++ b/llvm/docs/FAQ.rst
@@ -22,6 +22,13 @@ Yes. This is why we distribute LLVM under a less restrictive license than GPL,
 as explained in the first question above.
 
 
+Can I use AI coding tools, such as GitHub co-pilot, to write LLVM patches?
+--------------------------------------------------------------------------
+Yes, as long as the resulting work can be licensed under the project license, as
+covered in the :doc:`DeveloperPolicy`. Using an AI tool to reproduce copyrighted
+work does not rinse it of copyright and grant you the right to relicense it.
+
+
 Source Code
 ===========
 

>From 9c662c1468fbc4a8753187c10ce65e4cbe25ab99 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Wed, 4 Sep 2024 16:23:58 +0000
Subject: [PATCH 4/5] Add paragraph to encourage contributors to validate
 generated code before sending it for review

---
 llvm/docs/DeveloperPolicy.rst | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/docs/DeveloperPolicy.rst b/llvm/docs/DeveloperPolicy.rst
index abb55cd670591c..3f568f8372aa9e 100644
--- a/llvm/docs/DeveloperPolicy.rst
+++ b/llvm/docs/DeveloperPolicy.rst
@@ -1077,6 +1077,8 @@ If you have questions or comments about these topics, please ask on the
 please realize that most compiler developers are not lawyers, and therefore you
 will not be getting official legal advice.
 
+.. _LLVM Discourse forums: https://discourse.llvm.org
+
 Copyright
 ---------
 
@@ -1320,4 +1322,9 @@ intelligence tools to produce contributions, provided that they have the right
 to license that code under the project license. Contributions found to violate
 this policy will be removed just like any other offending contribution.
 
-.. _LLVM Discourse forums: https://discourse.llvm.org
+While the LLVM project has a liberal policy on AI tool use, contributors are
+considered responsible for their contributions. We encourage contributors to
+review all generated code before sending it for review to verify its
+correctness and to understand it so that they can answer questions during code
+review. Reviewing and maintaining generated code that the original contributor
+does not understand is not a good use of limited project resources.

>From f8afbb4c8b30b96e61098fe79250ffab003f8347 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Tue, 10 Sep 2024 16:14:03 -0700
Subject: [PATCH 5/5] Update llvm/docs/DeveloperPolicy.rst

Co-authored-by: maflcko <6399679+maflcko at users.noreply.github.com>
---
 llvm/docs/DeveloperPolicy.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/DeveloperPolicy.rst b/llvm/docs/DeveloperPolicy.rst
index 3f568f8372aa9e..0cae93eb544389 100644
--- a/llvm/docs/DeveloperPolicy.rst
+++ b/llvm/docs/DeveloperPolicy.rst
@@ -1317,7 +1317,7 @@ regenerate copyrighted material does not remove the copyright, and contributors
 are responsible for ensuring that such material does not appear in their
 contributions.
 
-As such, the LLVM policy is that contributors are permitted to to use artificial
+As such, the LLVM policy is that contributors are permitted to use artificial
 intelligence tools to produce contributions, provided that they have the right
 to license that code under the project license. Contributions found to violate
 this policy will be removed just like any other offending contribution.



More information about the cfe-commits mailing list