[llvm] Add PR check to suggest alternatives to using undef (PR #118506)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 08:05:22 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 7802fb5f514be327576b69569556ec9096e5fdd7...a1f3ad4d70203fe7b9a7e91d98b8da482c7119dc llvm/utils/git/code-format-helper.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- code-format-helper.py	2024-12-03 15:54:41.000000 +0000
+++ code-format-helper.py	2024-12-03 16:04:51.295669 +0000
@@ -323,22 +323,32 @@
 
     def filter_changed_files(self, changed_files: List[str]) -> List[str]:
         filtered_files = []
         for path in changed_files:
             _, ext = os.path.splitext(path)
-            if ext in (".cpp", ".c", ".h", ".hpp", ".hxx", ".cxx", ".inc", ".cppm", ".ll"):
+            if ext in (
+                ".cpp",
+                ".c",
+                ".h",
+                ".hpp",
+                ".hxx",
+                ".cxx",
+                ".inc",
+                ".cppm",
+                ".ll",
+            ):
                 filtered_files.append(path)
         return filtered_files
 
     def has_tool(self) -> bool:
         return True
 
     def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
         files = self.filter_changed_files(changed_files)
 
-        regex = '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)'
-        cmd = ['git', 'diff', '-U0', '--pickaxe-regex', '-S', regex]
+        regex = "([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)"
+        cmd = ["git", "diff", "-U0", "--pickaxe-regex", "-S", regex]
 
         if args.start_rev and args.end_rev:
             cmd.append(args.start_rev)
             cmd.append(args.end_rev)
 
@@ -351,17 +361,17 @@
         proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         sys.stdout.write(proc.stderr.decode("utf-8"))
         stdout = proc.stdout.decode("utf-8")
 
         files = []
-        for file in re.split('^diff --git ', stdout, 0, re.MULTILINE):
-            if re.search('^[+].*'+regex, file, re.MULTILINE):
-                files.append(re.match('a/([^ ]+)', file.splitlines()[0])[1])
+        for file in re.split("^diff --git ", stdout, 0, re.MULTILINE):
+            if re.search("^[+].*" + regex, file, re.MULTILINE):
+                files.append(re.match("a/([^ ]+)", file.splitlines()[0])[1])
 
         if files:
-            files = '\n'.join(files)
-            report = f'''
+            files = "\n".join(files)
+            report = f"""
 The following files introduce new uses of undef:
 {files}
 
 Undef is now deprecated and should only be used in the rare cases where no
 replacement is possible. For example, load of uninitialized memory yields undef.
@@ -380,11 +390,11 @@
 Use the following instead:
 define void @fn(i1 %cond) {{
   ...
   br i1 %cond, ...
 }}
-'''
+"""
             if args.verbose:
                 print(f"error: {self.name} failed")
                 print(report)
             return report
         else:

``````````

</details>


https://github.com/llvm/llvm-project/pull/118506


More information about the llvm-commits mailing list