Skip to content

Commit c476a4a

Browse files
authored
[Clang][OpenCL] Fix Missing -fdeclare-opencl-builtins When Using --save-temps (llvm#131017)
When compiling an OpenCL program directly with `clang` using `--save-temps`, an error may occur if the program contains OpenCL builtins: ``` test.cl:3:21: error: use of undeclared identifier 'get_global_id' 3 | unsigned int id = get_global_id(0); | ^ ``` This happens because the driver does not add `-fdeclare-opencl-builtins` when the input type is `TY_PP_CL`. This PR fixes the issue.
1 parent c8047c6 commit c476a4a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/Driver/Types.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,17 @@ bool types::isObjC(ID Id) {
226226
}
227227
}
228228

229-
bool types::isOpenCL(ID Id) { return Id == TY_CL || Id == TY_CLCXX; }
229+
bool types::isOpenCL(ID Id) {
230+
switch (Id) {
231+
default:
232+
return false;
233+
case TY_PP_CL:
234+
case TY_PP_CLCXX:
235+
case TY_CL:
236+
case TY_CLCXX:
237+
return true;
238+
}
239+
}
230240

231241
bool types::isCXX(ID Id) {
232242
switch (Id) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang -x cl %s --save-temps -### 2>&1 | FileCheck %s
2+
3+
// CHECK: "-fdeclare-opencl-builtins" {{.*}} "[[SRC:.+]].cli" "-x" "cl" "{{.*}}[[SRC]].cl"
4+
// CHECK-NEXT: "-fdeclare-opencl-builtins" {{.*}} "-x" "cl-cpp-output" "[[SRC]].cli"

0 commit comments

Comments
 (0)