Skip to content

[clang-format] Add 'cl' to enable OpenCL kernel file formatting #134529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2025

Conversation

wenju-he
Copy link
Contributor

@wenju-he wenju-he commented Apr 6, 2025

There are many .cl files in llvm repo. It would be great that clang-format can support it.

@llvmbot
Copy link
Member

llvmbot commented Apr 6, 2025

@llvm/pr-subscribers-clang-format

Author: Wenju He (wenju-he)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/134529.diff

1 Files Affected:

  • (modified) clang/tools/clang-format/git-clang-format (+1)
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 85eff4761e289..ba324b14ab80d 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -126,6 +126,7 @@ def main():
             "pb.txt",
             "textproto",
             "asciipb",  # TextProto
+            "cl", # OpenCL
         ]
     )
 

Copy link
Contributor

@mydeveloperday mydeveloperday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there are more places where this needs to be addressed if we are going to add it.

@mydeveloperday
Copy link
Contributor

i.e. clang-format-diff.py

@mydeveloperday
Copy link
Contributor

should we consider .ocl?

@wenju-he
Copy link
Contributor Author

wenju-he commented Apr 7, 2025

i.e. clang-format-diff.py

Thanks. I just find out that OpenCL support was already added in clang-format-diff.py by c49406d

@wenju-he
Copy link
Contributor Author

wenju-he commented Apr 7, 2025

I feel like there are more places where this needs to be addressed if we are going to add it.

I added support in language detection for OpenCL in 88c1174. It returns C language since OpenCL is based on C99 and C11 with restrictions, see https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html

@wenju-he wenju-he requested a review from mydeveloperday April 7, 2025 23:22
@wenju-he
Copy link
Contributor Author

wenju-he commented Apr 7, 2025

should we consider .ocl?

.ocl isn't used as file extension for OpenCL. See

.Case("cl", Language::OpenCL)

@owenca
Copy link
Contributor

owenca commented Apr 8, 2025

I feel like there are more places where this needs to be addressed if we are going to add it.

I added support in language detection for OpenCL in 88c1174. It returns C language since OpenCL is based on C99 and C11 with restrictions, see https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html

OpenCL is formatted as C++ now. Do we really need to change that? See #132832 for potential problems.

@wenju-he
Copy link
Contributor Author

wenju-he commented Apr 8, 2025

I feel like there are more places where this needs to be addressed if we are going to add it.

I added support in language detection for OpenCL in 88c1174. It returns C language since OpenCL is based on C99 and C11 with restrictions, see https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html

OpenCL is formatted as C++ now. Do we really need to change that? See #132832 for potential problems.

reverted. Thanks. Default should be better if it works better.

@wenju-he wenju-he requested a review from owenca April 8, 2025 07:51
@wenju-he
Copy link
Contributor Author

@owenca could you please help me to merge? Thanks. I don't have commit permission.

@owenca owenca merged commit 923da2b into llvm:main Apr 10, 2025
11 checks passed
@wenju-he wenju-he deleted the git-clang-format-OpenCL branch April 10, 2025 08:41
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…#134529)

There are many .cl files in llvm repo. It would be great that
clang-format can support it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants