Skip to content

Commit b00d5f7

Browse files
committed
[OpenCL][Sema] Fix builtin rewriting
This patch ensures built-in functions are rewritten using the proper parent declaration. Existing tests are modified to run in C++ mode to ensure the functionality works also with C++ for OpenCL while not increasing the testing runtime. llvm-svn: 365499
1 parent b1e511b commit b00d5f7

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

clang/include/clang/Basic/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,7 @@ BUILTIN(__builtin_coro_begin, "v*v*", "n")
14781478
BUILTIN(__builtin_coro_end, "bv*Ib", "n")
14791479
BUILTIN(__builtin_coro_suspend, "cIb", "n")
14801480
BUILTIN(__builtin_coro_param, "bv*v*", "n")
1481+
14811482
// OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
14821483
// We need the generic prototype, since the packet type could be anything.
14831484
LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
@@ -1513,6 +1514,8 @@ LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", OCLC20_LANG)
15131514
LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
15141515

15151516
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
1517+
// FIXME: Pointer parameters of OpenCL builtins should have their address space
1518+
// requirement defined.
15161519
LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
15171520
LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
15181521
LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,7 +5360,7 @@ static bool checkArgsForPlaceholders(Sema &S, MultiExprArg args) {
53605360
/// FunctionDecl is returned.
53615361
/// TODO: Handle pointer return types.
53625362
static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
5363-
const FunctionDecl *FDecl,
5363+
FunctionDecl *FDecl,
53645364
MultiExprArg ArgExprs) {
53655365

53665366
QualType DeclType = FDecl->getType();
@@ -5408,7 +5408,7 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
54085408
FunctionProtoType::ExtProtoInfo EPI;
54095409
QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
54105410
OverloadParams, EPI);
5411-
DeclContext *Parent = Context.getTranslationUnitDecl();
5411+
DeclContext *Parent = FDecl->getParent();
54125412
FunctionDecl *OverloadDecl = FunctionDecl::Create(Context, Parent,
54135413
FDecl->getLocation(),
54145414
FDecl->getLocation(),

clang/test/CodeGenOpenCL/builtins.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -finclude-default-header -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s
1+
// RUN: %clang_cc1 %s -finclude-default-header -cl-std=c++ -fblocks -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s
22

33
void testBranchingOnEnqueueKernel(queue_t default_queue, unsigned flags, ndrange_t ndrange) {
44
// Ensure `enqueue_kernel` can be branched upon.

clang/test/CodeGenOpenCL/pipe_builtin.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o - %s | FileCheck %s
22

33
// CHECK-DAG: %opencl.pipe_ro_t = type opaque
44
// CHECK-DAG: %opencl.pipe_wo_t = type opaque

clang/test/CodeGenOpenCL/to_addr_builtin.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=c++ -o - %s | FileCheck %s
22

33
// CHECK: %[[A:.*]] = type { float, float, float }
44
typedef struct {

0 commit comments

Comments
 (0)