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 origin/main...HEAD apply_comprehensive_fix.py 
final_apply.py final_apply_perfect.py final_logic_fix.py
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
--- apply_comprehensive_fix.py  2026-02-13 16:39:34.000000 +0000
+++ apply_comprehensive_fix.py  2026-02-13 16:41:10.676018 +0000
@@ -1,66 +1,78 @@
 import sys
 import re
 
-file_path = 'clang/lib/Sema/SemaTemplate.cpp'
-with open(file_path, 'r') as f:
+file_path = "clang/lib/Sema/SemaTemplate.cpp"
+with open(file_path, "r") as f:
     content = f.read()
 
 # 1. Apply Arity Gatekeeper
-gatekeeper = '''  if (Converted.size() < BTD->getTemplateParameters()->size())
-    return QualType();\n\n'''
-func_start_pattern = r'(static QualType 
checkBuiltinTemplateIdType\(.*?TemplateArgumentListInfo\s*&TemplateArgs\)\s*\{)\n'
-content = re.sub(func_start_pattern, r'\1\n' + gatekeeper, content, 
flags=re.DOTALL)
+gatekeeper = """  if (Converted.size() < BTD->getTemplateParameters()->size())
+    return QualType();\n\n"""
+func_start_pattern = r"(static QualType 
checkBuiltinTemplateIdType\(.*?TemplateArgumentListInfo\s*&TemplateArgs\)\s*\{)\n"
+content = re.sub(func_start_pattern, r"\1\n" + gatekeeper, content, 
flags=re.DOTALL)
 
 # 2. Fix BTK__make_integer_seq
-make_integer_seq_start = r'case BTK__make_integer_seq: \{\n\s*// 
Specializations of __make_integer_seq<S, T, N> are treated like\n\s*// S<T, 0, 
\.\.\., N-1>\.'
-make_integer_seq_repl = r'''case BTK__make_integer_seq: {
+make_integer_seq_start = r"case BTK__make_integer_seq: \{\n\s*// 
Specializations of __make_integer_seq<S, T, N> are treated like\n\s*// S<T, 0, 
\.\.\., N-1>\."
+make_integer_seq_repl = r"""case BTK__make_integer_seq: {
     assert(Converted.size() == 3);
     if (Converted[2].isDependent())
       return QualType();
 
     // Specializations of __make_integer_seq<S, T, N> are treated like
-    // S<T, 0, ..., N-1>.'''
+    // S<T, 0, ..., N-1>."""
 content = re.sub(make_integer_seq_start, make_integer_seq_repl, content)
 
 # 3. Fix the integral type check
-integral_check_pattern = r'if \(!OrigType->isIntegralType\(Context\)\) \{'
-integral_check_repl = 'if (!OrigType->isDependentType() && 
!OrigType->isIntegralType(Context)) {'
+integral_check_pattern = r"if \(!OrigType->isIntegralType\(Context\)\) \{"
+integral_check_repl = (
+    "if (!OrigType->isDependentType() && !OrigType->isIntegralType(Context)) {"
+)
 content = re.sub(integral_check_pattern, integral_check_repl, content)
 
 # 4. Remove redundant n check
-redundant_n_check = r'TemplateArgument NumArgsArg = Converted\[2\];\n\s*if 
\(NumArgsArg\.isDependent\(\)\)\n\s*return QualType\(\);'
-content = re.sub(redundant_n_check, 'TemplateArgument NumArgsArg = 
Converted[2];', content)
+redundant_n_check = r"TemplateArgument NumArgsArg = Converted\[2\];\n\s*if 
\(NumArgsArg\.isDependent\(\)\)\n\s*return QualType\(\);"
+content = re.sub(
+    redundant_n_check, "TemplateArgument NumArgsArg = Converted[2];", content
+)
 
 # 5. Fix BTK__type_pack_element
-type_pack_element_start = r'case BTK__type_pack_element: 
\{\n\s*TemplateArgument IndexArg = Converted\[0\], Ts = Converted\[1\];'
-type_pack_element_repl = r'''case BTK__type_pack_element: {
+type_pack_element_start = r"case BTK__type_pack_element: 
\{\n\s*TemplateArgument IndexArg = Converted\[0\], Ts = Converted\[1\];"
+type_pack_element_repl = r"""case BTK__type_pack_element: {
     assert(Converted.size() == 2 &&
            "__type_pack_element should be given an index and a parameter 
pack");
     if (Converted[0].isDependent() || Converted[1].isDependent())
       return QualType();
 
-    TemplateArgument IndexArg = Converted[0], Ts = Converted[1];'''
+    TemplateArgument IndexArg = Converted[0], Ts = Converted[1];"""
 content = re.sub(type_pack_element_start, type_pack_element_repl, content)
-content = re.sub(r'if \(IndexArg\.isDependent\(\) \|\| 
Ts\.isDependent\(\)\)\n\s*return QualType\(\);\n\n', '', content)
+content = re.sub(
+    r"if \(IndexArg\.isDependent\(\) \|\| Ts\.isDependent\(\)\)\n\s*return 
QualType\(\);\n\n",
+    "",
+    content,
+)
 
 # 6. Fix BTK__builtin_common_type
-common_type_start = r'case BTK__builtin_common_type: \{\n\s*if 
\(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return C\.isDependent\(\); 
\}\)\)\n\s*return QualType\(\);'
-common_type_repl = r'''case BTK__builtin_common_type: {
+common_type_start = r"case BTK__builtin_common_type: \{\n\s*if 
\(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return C\.isDependent\(\); 
\}\)\)\n\s*return QualType\(\);"
+common_type_repl = r"""case BTK__builtin_common_type: {
     assert(Converted.size() == 4);
     if (Converted[3].isDependent())
-      return QualType();'''
+      return QualType();"""
 content = re.sub(common_type_start, common_type_repl, content)
 
 # 7. Fix BTK__hlsl_spirv_type
-spirv_type_start = r'case BTK__hlsl_spirv_type: \{\n\s*if 
\(!Context\.getTargetInfo\(\)\.getTriple\(\)\.isSPIRV\(\)\) \{'
-spirv_type_repl = r'''case BTK__hlsl_spirv_type: {
+spirv_type_start = r"case BTK__hlsl_spirv_type: \{\n\s*if 
\(!Context\.getTargetInfo\(\)\.getTriple\(\)\.isSPIRV\(\)\) \{"
+spirv_type_repl = r"""case BTK__hlsl_spirv_type: {
     assert(Converted.size() == 4);
     if (llvm::any_of(Converted, [](const TemplateArgument &A) { return 
A.isDependent(); }))
       return QualType();
 
-    if (!Context.getTargetInfo().getTriple().isSPIRV()) {'''
+    if (!Context.getTargetInfo().getTriple().isSPIRV()) {"""
 content = re.sub(spirv_type_start, spirv_type_repl, content)
-content = re.sub(r'if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);\n\n', '', content)
+content = re.sub(
+    r"if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);\n\n",
+    "",
+    content,
+)
 
-with open(file_path, 'w') as f:
+with open(file_path, "w") as f:
     f.write(content)
--- final_apply.py      2026-02-13 16:39:34.000000 +0000
+++ final_apply.py      2026-02-13 16:41:10.696965 +0000
@@ -1,66 +1,86 @@
 import sys
 import os
 import re
 
-file_path = 'clang/lib/Sema/SemaTemplate.cpp'
-with open(file_path, 'r') as f:
+file_path = "clang/lib/Sema/SemaTemplate.cpp"
+with open(file_path, "r") as f:
     content = f.read()
 
 # Reset to ensure we are working on a clean slate
 # (The user should have reset origin/main before running this)
 
 # 1. Add Arity Gatekeeper
 gatekeeper = """  if (Converted.size() < BTD->getTemplateParameters()->size())
     return QualType();\n\n"""
-func_decl = r'(static QualType 
checkBuiltinTemplateIdType\(.*?TemplateArgumentListInfo &TemplateArgs\) \{)\n'
-content = re.sub(func_decl, r'\1\n' + gatekeeper, content, flags=re.DOTALL)
+func_decl = r"(static QualType 
checkBuiltinTemplateIdType\(.*?TemplateArgumentListInfo &TemplateArgs\) \{)\n"
+content = re.sub(func_decl, r"\1\n" + gatekeeper, content, flags=re.DOTALL)
 
 # 2. BTK__make_integer_seq
 # Insert check at the start of case, and remove the internal one.
-make_seq_pattern = r'(case BTK__make_integer_seq: \{)\n'
-make_seq_repl = r'\1\n    assert(Converted.size() == 3);\n    if 
(Converted[2].isDependent())\n      return QualType();\n'
+make_seq_pattern = r"(case BTK__make_integer_seq: \{)\n"
+make_seq_repl = r"\1\n    assert(Converted.size() == 3);\n    if 
(Converted[2].isDependent())\n      return QualType();\n"
 content = re.sub(make_seq_pattern, make_seq_repl, content)
 
-redundant_n_check = r'if \(NumArgsArg\.isDependent\(\)\)\n\s*return 
QualType\(\);'
-content = re.sub(redundant_n_check, '', content)
+redundant_n_check = r"if \(NumArgsArg\.isDependent\(\)\)\n\s*return 
QualType\(\);"
+content = re.sub(redundant_n_check, "", content)
 
 # 3. BTK__type_pack_element
 # It already has an assertion. Move the dependent check up.
-# Trunk has: 
+# Trunk has:
 # assert(Converted.size() == 2 && ...);
 # TemplateArgument IndexArg = Converted[0], Ts = Converted[1];
 # if (IndexArg.isDependent() || Ts.isDependent()) return QualType();
 
 # We want it to be:
 # assert(Converted.size() == 2 && ...);
 # if (Converted[0].isDependent() || Converted[1].isDependent()) return 
QualType();
 # TemplateArgument IndexArg = Converted[0], Ts = Converted[1];
 
-type_pack_search = r'case BTK__type_pack_element: 
\{.*?\n\s*assert\(Converted\.size\(\) == 2 &&.*?\);\n\s*'
+type_pack_search = r"case BTK__type_pack_element: 
\{.*?\n\s*assert\(Converted\.size\(\) == 2 &&.*?\);\n\s*"
 type_pack_repl = r'case BTK__type_pack_element: {\n    assert(Converted.size() 
== 2 &&\n           "__type_pack_element should be given an index and a 
parameter pack");\n    if (Converted[0].isDependent() || 
Converted[1].isDependent())\n      return QualType();\n\n'
-content = re.sub(r'case BTK__type_pack_element: 
\{.*?assert\(Converted\.size\(\) == 2 &&.*?\);\s*', type_pack_repl, content, 
flags=re.DOTALL)
+content = re.sub(
+    r"case BTK__type_pack_element: \{.*?assert\(Converted\.size\(\) == 2 
&&.*?\);\s*",
+    type_pack_repl,
+    content,
+    flags=re.DOTALL,
+)
 
 # Remove the now-redundant assignment if it followed immediately
-content = re.sub(r'TemplateArgument IndexArg = Converted\[0\], Ts = 
Converted\[1\];\n\s*if \(IndexArg\.isDependent\(\) \|\| 
Ts\.isDependent\(\)\)\n\s*return QualType\(\);', 'TemplateArgument IndexArg = 
Converted[0], Ts = Converted[1];', content)
+content = re.sub(
+    r"TemplateArgument IndexArg = Converted\[0\], Ts = Converted\[1\];\n\s*if 
\(IndexArg\.isDependent\(\) \|\| Ts\.isDependent\(\)\)\n\s*return 
QualType\(\);",
+    "TemplateArgument IndexArg = Converted[0], Ts = Converted[1];",
+    content,
+)
 
 # 4. BTK__builtin_common_type
-# Trunk has: 
+# Trunk has:
 # assert(Converted.size() == 4);
 # if (llvm::any_of(Converted, ...)) return QualType();
 # We change it to only check Converted[3].
-content = re.sub(r'if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);', 'if 
(Converted[3].isDependent())\n      return QualType();', content, count=1)
+content = re.sub(
+    r"if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);",
+    "if (Converted[3].isDependent())\n      return QualType();",
+    content,
+    count=1,
+)
 
 # 5. BTK__hlsl_spirv_type
 # Trunk has any_of. We keep it but ensure it's at the top of the case area.
 # Wait, I already removed one any_of. Let's find the second one.
 # Actually, I'll just be explicit.
-spirv_search = r'case BTK__hlsl_spirv_type: 
\{.*?\n\s*assert\(Converted\.size\(\) == 4\);'
-spirv_repl = r'case BTK__hlsl_spirv_type: {\n    assert(Converted.size() == 
4);\n    if (llvm::any_of(Converted, [](const TemplateArgument &A) { return 
A.isDependent(); }))\n      return QualType();\n\n'
+spirv_search = (
+    r"case BTK__hlsl_spirv_type: \{.*?\n\s*assert\(Converted\.size\(\) == 4\);"
+)
+spirv_repl = r"case BTK__hlsl_spirv_type: {\n    assert(Converted.size() == 
4);\n    if (llvm::any_of(Converted, [](const TemplateArgument &A) { return 
A.isDependent(); }))\n      return QualType();\n\n"
 content = re.sub(spirv_search, spirv_repl, content, flags=re.DOTALL)
 
 # Cleanup any remaining any_of in hlsl case
-content = re.sub(r'if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);', '', content)
+content = re.sub(
+    r"if \(llvm::any_of\(Converted, \[\]\(auto &C\) \{ return 
C\.isDependent\(\); \}\)\)\n\s*return QualType\(\);",
+    "",
+    content,
+)
 
-with open(file_path, 'w') as f:
+with open(file_path, "w") as f:
     f.write(content)
 print("Applied successfully.")
--- final_apply_perfect.py      2026-02-13 16:39:34.000000 +0000
+++ final_apply_perfect.py      2026-02-13 16:41:10.720350 +0000
@@ -1,67 +1,71 @@
 import sys
 import os
 
-file_path = 'clang/lib/Sema/SemaTemplate.cpp'
+file_path = "clang/lib/Sema/SemaTemplate.cpp"
 
 # Read the original file from git to ensure a clean base
-os.system(f'git checkout {file_path}')
+os.system(f"git checkout {file_path}")
 
-with open(file_path, 'r') as f:
+with open(file_path, "r") as f:
     lines = f.readlines()
 
 new_lines = []
 skip_until = None
 
 i = 0
 while i < len(lines):
     line = lines[i]
-    
+
     # 1. Insert Smart Gatekeeper at the beginning of checkBuiltinTemplateIdType
-    if 'static QualType checkBuiltinTemplateIdType(' in line:
+    if "static QualType checkBuiltinTemplateIdType(" in line:
         new_lines.append(line)
-        while 'TemplateArgumentListInfo &TemplateArgs) {' not in lines[i]:
+        while "TemplateArgumentListInfo &TemplateArgs) {" not in lines[i]:
             i += 1
             new_lines.append(lines[i])
-        new_lines.append('  TemplateParameterList *Params = 
BTD->getTemplateParameters();\n')
-        new_lines.append('  unsigned RequiredArgs = Params->size();\n')
-        new_lines.append('  if (Params->hasParameterPack()) {\n')
-        new_lines.append('    if (Converted.size() < RequiredArgs)\n')
-        new_lines.append('      return QualType();\n')
-        new_lines.append('  } else {\n')
-        new_lines.append('    if (Converted.size() != RequiredArgs)\n')
-        new_lines.append('      return QualType();\n')
-        new_lines.append('  }\n\n')
+        new_lines.append(
+            "  TemplateParameterList *Params = BTD->getTemplateParameters();\n"
+        )
+        new_lines.append("  unsigned RequiredArgs = Params->size();\n")
+        new_lines.append("  if (Params->hasParameterPack()) {\n")
+        new_lines.append("    if (Converted.size() < RequiredArgs)\n")
+        new_lines.append("      return QualType();\n")
+        new_lines.append("  } else {\n")
+        new_lines.append("    if (Converted.size() != RequiredArgs)\n")
+        new_lines.append("      return QualType();\n")
+        new_lines.append("  }\n\n")
         i += 1
         continue
 
     # 2. __make_integer_seq: early isDependent check
-    if 'case BTK__make_integer_seq: {' in line:
+    if "case BTK__make_integer_seq: {" in line:
         new_lines.append(line)
-        new_lines.append('    if (Converted[2].isDependent())\n')
-        new_lines.append('      return QualType();\n')
+        new_lines.append("    if (Converted[2].isDependent())\n")
+        new_lines.append("      return QualType();\n")
         i += 1
         continue
 
     # 3. Handle OrigType->isIntegralType(Context) check to include 
!OrigType->isDependentType()
-    if 'if (!OrigType->isIntegralType(Context)) {' in line:
-        new_lines.append('    if (!OrigType->isDependentType() && 
!OrigType->isIntegralType(Context)) {\n')
+    if "if (!OrigType->isIntegralType(Context)) {" in line:
+        new_lines.append(
+            "    if (!OrigType->isDependentType() && 
!OrigType->isIntegralType(Context)) {\n"
+        )
         i += 1
         continue
 
     # 4. Remove the redundant NumArgsArg.isDependent check lower down (if it 
exists in trunk)
     # Trunk usually doesn't have it, but we'll be safe.
-    
+
     new_lines.append(line)
     i += 1
 
-with open(file_path, 'w') as f:
+with open(file_path, "w") as f:
     f.writelines(new_lines)
 
 # Apply the test file fix
-test_file = 'clang/test/SemaCXX/builtin_templates_invalid_parameters.cpp'
-test_content = '''// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+test_file = "clang/test/SemaCXX/builtin_templates_invalid_parameters.cpp"
+test_content = """// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 // expected-error@* 2 {{template argument for non-type template parameter must 
be an expression}}
 
 using SizeT = decltype(sizeof(int));
 
 // Dependent cases that previously crashed but now return QualType() 
gracefully.
@@ -98,8 +102,8 @@
 // Verify that too_few_args doesn't crash on instantiation either
 // (It should just be an invalid type)
 template <SizeT I> struct Wrap {
   using type = too_few_args<I>;
 };
-'''
-with open(test_file, 'w') as f:
+"""
+with open(test_file, "w") as f:
     f.write(test_content)
--- final_logic_fix.py  2026-02-13 16:39:34.000000 +0000
+++ final_logic_fix.py  2026-02-13 16:41:10.732851 +0000
@@ -1,20 +1,26 @@
 import sys
 import re
 
-file_path = 'clang/lib/Sema/SemaTemplate.cpp'
-with open(file_path, 'r') as f:
+file_path = "clang/lib/Sema/SemaTemplate.cpp"
+with open(file_path, "r") as f:
     content = f.read()
 
 # 1. Refine BTK__make_integer_seq: Only bail if N (Converted[2]) is dependent.
-pattern1 = r'if \(Converted\[1\]\.isDependent\(\) \|\| 
Converted\[2\]\.isDependent\(\)\)\s*return QualType\(\);'
-content = re.sub(pattern1, 'if (Converted[2].isDependent())\n      return 
QualType();', content)
+pattern1 = r"if \(Converted\[1\]\.isDependent\(\) \|\| 
Converted\[2\]\.isDependent\(\)\)\s*return QualType\(\);"
+content = re.sub(
+    pattern1, "if (Converted[2].isDependent())\n      return QualType();", 
content
+)
 
 # 2. Remove the assertion that OrigType is not dependent
-content = content.replace('    assert(!OrigType->isDependentType());\n', '')
+content = content.replace("    assert(!OrigType->isDependentType());\n", "")
 
 # 3. Add a check for IntegralType ONLY if it is NOT dependent
-pattern2 = r'if \(!OrigType->isIntegralType\(Context\)\) \{'
-content = re.sub(pattern2, 'if (!OrigType->isDependentType() && 
!OrigType->isIntegralType(Context)) {', content)
+pattern2 = r"if \(!OrigType->isIntegralType\(Context\)\) \{"
+content = re.sub(
+    pattern2,
+    "if (!OrigType->isDependentType() && !OrigType->isIntegralType(Context)) 
{",
+    content,
+)
 
-with open(file_path, 'w') as f:
+with open(file_path, "w") as f:
     f.write(content)

``````````

</details>


https://github.com/llvm/llvm-project/pull/180261
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to