diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 100dc10cc11e8..db8e6bf0ed15b 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace clang; using namespace std::placeholders; @@ -67,6 +68,21 @@ static constexpr llvm::StringLiteral InitSpecConstantsBuffer = static constexpr llvm::StringLiteral FinalizeMethodName = "__finalize"; static constexpr llvm::StringLiteral LibstdcxxFailedAssertion = "__failed_assertion"; +static std::set LibdeviceCmathSet = { + "scalbnf", "scalbn", "logf", "log", "expf", "exp", + "log10f", "log10", "modff", "modf", "exp2f", "exp2", + "expm1f", "expm1", "ilogbf", "ilogb", "log1pf", "log1p", + "log2f", "log2", "logbf", "logb", "sqrtf", "sqrt", + "cbrtf", "cbrt", "erff", "erf", "erfcf", "erfc", + "tgammaf", "tgamma", "lgammaf", "lgamma", "fmodf", "fmod", + "remainderf", "remainder", "remquof", "remquo", "nextafterf", "nextafter", + "fdimf", "fdim", "fmaf", "fma", "sinf", "sin", + "cosf", "cos", "tanf", "tan", "asinf", "asin", + "acosf", "acos", "atanf", "atan", "powf", "pow", + "atan2f", "atan2", "sinhf", "sinh", "coshf", "cosh", + "tanhf", "tanh", "asinhf", "asinh", "acoshf", "acosh", + "atanhf", "atanh", "frexpf", "frexp", "ldexpf", "ldexp", + "hypotf", "hypot"}; constexpr unsigned MaxKernelArgsSize = 2048; static bool isSyclType(QualType Ty, SYCLTypeAttr::SYCLType TypeName) { @@ -493,6 +509,10 @@ static bool isSYCLUndefinedAllowed(const FunctionDecl *Callee, if (!Callee->getIdentifier()) return false; + if (LibdeviceCmathSet.count(Callee->getName().str()) && + SrcMgr.isInSystemHeader(Callee->getLocation())) + return true; + // libstdc++-11 introduced an undefined function "void __failed_assertion()" // which may lead to SemaSYCL check failure. However, this undefined function // is used to trigger some compilation error when the check fails at compile diff --git a/sycl/include/sycl/builtins.hpp b/sycl/include/sycl/builtins.hpp index 92814bdafd7d4..53114dc5d7737 100644 --- a/sycl/include/sycl/builtins.hpp +++ b/sycl/include/sycl/builtins.hpp @@ -25,89 +25,9 @@ extern "C" { extern __DPCPP_SYCL_EXTERNAL int abs(int x); extern __DPCPP_SYCL_EXTERNAL long int labs(long int x); extern __DPCPP_SYCL_EXTERNAL long long int llabs(long long int x); - extern __DPCPP_SYCL_EXTERNAL div_t div(int x, int y); extern __DPCPP_SYCL_EXTERNAL ldiv_t ldiv(long int x, long int y); extern __DPCPP_SYCL_EXTERNAL lldiv_t lldiv(long long int x, long long int y); -extern __DPCPP_SYCL_EXTERNAL float scalbnf(float x, int n); -extern __DPCPP_SYCL_EXTERNAL double scalbn(double x, int n); -extern __DPCPP_SYCL_EXTERNAL float logf(float x); -extern __DPCPP_SYCL_EXTERNAL double log(double x); -extern __DPCPP_SYCL_EXTERNAL float expf(float x); -extern __DPCPP_SYCL_EXTERNAL double exp(double x); -extern __DPCPP_SYCL_EXTERNAL float log10f(float x); -extern __DPCPP_SYCL_EXTERNAL double log10(double x); -extern __DPCPP_SYCL_EXTERNAL float modff(float x, float *intpart); -extern __DPCPP_SYCL_EXTERNAL double modf(double x, double *intpart); -extern __DPCPP_SYCL_EXTERNAL float exp2f(float x); -extern __DPCPP_SYCL_EXTERNAL double exp2(double x); -extern __DPCPP_SYCL_EXTERNAL float expm1f(float x); -extern __DPCPP_SYCL_EXTERNAL double expm1(double x); -extern __DPCPP_SYCL_EXTERNAL int ilogbf(float x); -extern __DPCPP_SYCL_EXTERNAL int ilogb(double x); -extern __DPCPP_SYCL_EXTERNAL float log1pf(float x); -extern __DPCPP_SYCL_EXTERNAL double log1p(double x); -extern __DPCPP_SYCL_EXTERNAL float log2f(float x); -extern __DPCPP_SYCL_EXTERNAL double log2(double x); -extern __DPCPP_SYCL_EXTERNAL float logbf(float x); -extern __DPCPP_SYCL_EXTERNAL double logb(double x); -extern __DPCPP_SYCL_EXTERNAL float sqrtf(float x); -extern __DPCPP_SYCL_EXTERNAL double sqrt(double x); -extern __DPCPP_SYCL_EXTERNAL float cbrtf(float x); -extern __DPCPP_SYCL_EXTERNAL double cbrt(double x); -extern __DPCPP_SYCL_EXTERNAL float erff(float x); -extern __DPCPP_SYCL_EXTERNAL double erf(double x); -extern __DPCPP_SYCL_EXTERNAL float erfcf(float x); -extern __DPCPP_SYCL_EXTERNAL double erfc(double x); -extern __DPCPP_SYCL_EXTERNAL float tgammaf(float x); -extern __DPCPP_SYCL_EXTERNAL double tgamma(double x); -extern __DPCPP_SYCL_EXTERNAL float lgammaf(float x); -extern __DPCPP_SYCL_EXTERNAL double lgamma(double x); -extern __DPCPP_SYCL_EXTERNAL float fmodf(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double fmod(double x, double y); -extern __DPCPP_SYCL_EXTERNAL float remainderf(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double remainder(double x, double y); -extern __DPCPP_SYCL_EXTERNAL float remquof(float x, float y, int *q); -extern __DPCPP_SYCL_EXTERNAL double remquo(double x, double y, int *q); -extern __DPCPP_SYCL_EXTERNAL float nextafterf(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double nextafter(double x, double y); -extern __DPCPP_SYCL_EXTERNAL float fdimf(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double fdim(double x, double y); -extern __DPCPP_SYCL_EXTERNAL float fmaf(float x, float y, float z); -extern __DPCPP_SYCL_EXTERNAL double fma(double x, double y, double z); -extern __DPCPP_SYCL_EXTERNAL float sinf(float x); -extern __DPCPP_SYCL_EXTERNAL double sin(double x); -extern __DPCPP_SYCL_EXTERNAL float cosf(float x); -extern __DPCPP_SYCL_EXTERNAL double cos(double x); -extern __DPCPP_SYCL_EXTERNAL float tanf(float x); -extern __DPCPP_SYCL_EXTERNAL double tan(double x); -extern __DPCPP_SYCL_EXTERNAL float asinf(float x); -extern __DPCPP_SYCL_EXTERNAL double asin(double x); -extern __DPCPP_SYCL_EXTERNAL float acosf(float x); -extern __DPCPP_SYCL_EXTERNAL double acos(double x); -extern __DPCPP_SYCL_EXTERNAL float atanf(float x); -extern __DPCPP_SYCL_EXTERNAL double atan(double x); -extern __DPCPP_SYCL_EXTERNAL float powf(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double pow(double x, double y); -extern __DPCPP_SYCL_EXTERNAL float atan2f(float x, float y); -extern __DPCPP_SYCL_EXTERNAL double atan2(double x, double y); - -extern __DPCPP_SYCL_EXTERNAL float sinhf(float x); -extern __DPCPP_SYCL_EXTERNAL double sinh(double x); -extern __DPCPP_SYCL_EXTERNAL float coshf(float x); -extern __DPCPP_SYCL_EXTERNAL double cosh(double x); -extern __DPCPP_SYCL_EXTERNAL float tanhf(float x); -extern __DPCPP_SYCL_EXTERNAL double tanh(double x); -extern __DPCPP_SYCL_EXTERNAL float asinhf(float x); -extern __DPCPP_SYCL_EXTERNAL double asinh(double x); -extern __DPCPP_SYCL_EXTERNAL float acoshf(float x); -extern __DPCPP_SYCL_EXTERNAL double acosh(double x); -extern __DPCPP_SYCL_EXTERNAL float atanhf(float x); -extern __DPCPP_SYCL_EXTERNAL double atanh(double x); -extern __DPCPP_SYCL_EXTERNAL double frexp(double x, int *exp); -extern __DPCPP_SYCL_EXTERNAL double ldexp(double x, int exp); -extern __DPCPP_SYCL_EXTERNAL double hypot(double x, double y); - extern __DPCPP_SYCL_EXTERNAL void *memcpy(void *dest, const void *src, size_t n); extern __DPCPP_SYCL_EXTERNAL void *memset(void *dest, int c, size_t n); @@ -604,10 +524,6 @@ extern __DPCPP_SYCL_EXTERNAL void __assert_fail(const char *expr, const char *file, unsigned int line, const char *func); -extern __DPCPP_SYCL_EXTERNAL float frexpf(float x, int *exp); -extern __DPCPP_SYCL_EXTERNAL float ldexpf(float x, int exp); -extern __DPCPP_SYCL_EXTERNAL float hypotf(float x, float y); - // MS UCRT supports most of the C standard library but is // an exception. extern __DPCPP_SYCL_EXTERNAL float cimagf(float __complex__ z);