Skip to content

Commit 88c1174

Browse files
committed
return C language format style for OpenCL
1 parent ac389b8 commit 88c1174

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

clang/lib/Format/Format.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4094,6 +4094,9 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
40944094
FileName.ends_with_insensitive(".vh")) {
40954095
return FormatStyle::LK_Verilog;
40964096
}
4097+
// OpenCL is based on C99 and C11.
4098+
if (FileName.ends_with(".cl"))
4099+
return FormatStyle::LK_C;
40974100
return FormatStyle::LK_Cpp;
40984101
}
40994102

@@ -4121,6 +4124,8 @@ static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
41214124
return FormatStyle::LK_Cpp;
41224125
if (Text == "ObjC")
41234126
return FormatStyle::LK_ObjC;
4127+
if (Text == "OpenCL")
4128+
return FormatStyle::LK_C;
41244129
}
41254130

41264131
return FormatStyle::LK_None;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: clang-format -assume-filename=foo.cl -dump-config | FileCheck %s
2+
3+
// RUN: clang-format -dump-config - < %s | FileCheck %s
4+
5+
// CHECK: Language: C
6+
7+
void foo() {}

clang/test/Format/lit.local.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ config.suffixes = [
2020
".textpb",
2121
".asciipb",
2222
".td",
23-
".test"
23+
".test",
24+
".cl"
2425
]
2526

2627
# AIX 'diff' command doesn't support --strip-trailing-cr, but the internal

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25187,6 +25187,9 @@ TEST_F(FormatTest, GetLanguageByComment) {
2518725187
EXPECT_EQ(FormatStyle::LK_ObjC,
2518825188
guessLanguage("foo.h", "// clang-format Language: ObjC\n"
2518925189
"int i;"));
25190+
EXPECT_EQ(FormatStyle::LK_C,
25191+
guessLanguage("foo.h", "// clang-format Language: OpenCL\n"
25192+
"int i;"));
2519025193
}
2519125194

2519225195
TEST_F(FormatTest, TypenameMacros) {

0 commit comments

Comments
 (0)