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 + +}