-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang][OpenCL] Fix Missing -fdeclare-opencl-builtins
When Using --save-temps
#131017
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
Conversation
…-save-temps` 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.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Shilei Tian (shiltian) ChangesWhen compiling an OpenCL program directly with
This happens because the driver does not add Full diff: https://github.com/llvm/llvm-project/pull/131017.diff 2 Files Affected:
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index eaca74a7b5529..08866e89ea447 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -226,7 +226,17 @@ bool types::isObjC(ID Id) {
}
}
-bool types::isOpenCL(ID Id) { return Id == TY_CL || Id == TY_CLCXX; }
+bool types::isOpenCL(ID Id) {
+ switch (Id) {
+ default:
+ return false;
+ case TY_PP_CL:
+ case TY_PP_CLCXX:
+ case TY_CL:
+ case TY_CLCXX:
+ return true;
+ }
+}
bool types::isCXX(ID Id) {
switch (Id) {
diff --git a/clang/test/Driver/opencl-aot-compilation.cl b/clang/test/Driver/opencl-aot-compilation.cl
new file mode 100644
index 0000000000000..eba658619b7f8
--- /dev/null
+++ b/clang/test/Driver/opencl-aot-compilation.cl
@@ -0,0 +1,4 @@
+// RUN: %clang -x cl %s --save-temps -### 2>&1 | FileCheck %s
+
+// CHECK: "-fdeclare-opencl-builtins" {{.*}} "[[SRC:.+]].cli" "-x" "cl" "{{.*}}[[SRC]].cl"
+// CHECK-NEXT: "-fdeclare-opencl-builtins" {{.*}} "-x" "cl-cpp-output" "[[SRC]].cli"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, though I don't know why we have a special flag for what is essentially a header.
Yeah these are implemented in bitcode file, therefore it needs the front end to be able to recognize it instead of treating it as an unknown symbol. |
In a normal world they would just be in a header and then the library would get linked in later. |
These are not implemented in Bitcode linked in later. Tablegen emits a table clang directly consumes to pre-declare since it's faster than parsing the builtin header |
…-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.
When compiling an OpenCL program directly with
clang
using--save-temps
, anerror may occur if the program contains OpenCL builtins:
This happens because the driver does not add
-fdeclare-opencl-builtins
whenthe input type is
TY_PP_CL
. This PR fixes the issue.