[PATCH] Sema: Accept pointers to any address space for builtin functions
Tom Stellard
thomas.stellard at amd.com
Thu Mar 5 07:28:07 PST 2015
Hi rsmith, arsenm, reames, theraven,
As long as they don't have an address space explicitly defined.
This allows builtins with pointer arguments to be used with OpenCL.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D8082
Files:
include/clang/Basic/Builtins.def
lib/Sema/SemaExpr.cpp
test/Sema/builtins.cl
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -56,7 +56,8 @@
// I -> Required to constant fold to an integer constant expression.
//
// Types may be postfixed with the following modifiers:
-// * -> pointer (optionally followed by an address space number)
+// * -> pointer (optionally followed by an address space number, if no address
+// space is specified than any address space will be accepted)
// & -> reference (optionally followed by an address space number)
// C -> const
// D -> volatile
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4383,6 +4383,26 @@
if (CFAudited)
Entity.setParameterCFAudited();
+ // If a builtin function has a pointer argument with no explicit address
+ // space, than it should be able to accept a pointer to any address
+ // space as input.
+ if (FDecl && FDecl->getBuiltinID() &&
+ Param->getType()->isPointerType() &&
+ !Param->getType().getQualifiers().hasAddressSpace()) {
+
+ Expr *PtrArg = DefaultFunctionArrayLvalueConversion(Arg).get();
+ QualType PtrTy = PtrArg->getType();
+ if (PtrTy->isPointerType()) {
+ QualType PointeeType = PtrTy->getPointeeType();
+ if (PointeeType.getQualifiers().hasAddressSpace()) {
+
+ Arg = ImplicitCastExpr::Create(Context, Param->getType(),
+ CK_AddressSpaceConversion, PtrArg,
+ nullptr, VK_RValue);
+ }
+ }
+ }
+
ExprResult ArgE = PerformCopyInitialization(
Entity, SourceLocation(), Arg, IsListInitialization, AllowExplicit);
if (ArgE.isInvalid())
Index: test/Sema/builtins.cl
===================================================================
--- /dev/null
+++ test/Sema/builtins.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+
+kernel void test(global float *out, global float *in, global int* in2) {
+
+ out[0] = __builtin_nanf(""); // expected-no-diagnostics
+ __builtin_memcpy(out, in, 32); // expected-no-diagnostics
+ out[0] = __builtin_frexpf(in[0], in2); // expected-no-diagnostics
+
+}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8082.21277.patch
Type: text/x-patch
Size: 2408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150305/ea6a718b/attachment.bin>
More information about the llvm-commits
mailing list