зеркало из https://github.com/microsoft/clang-1.git
OpenCL: if double precision floating point constant encountered
without cl_khr_fp64, warn and cast to single precision git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127476 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
f4e3cfbe8a
Коммит
f4f7cb814f
|
@ -30,6 +30,8 @@ def warn_float_overflow : Warning<
|
|||
def warn_float_underflow : Warning<
|
||||
"magnitude of floating-point constant too small for type %0; minimum is %1">,
|
||||
InGroup<LiteralRange>;
|
||||
def warn_double_const_requires_fp64 : Warning<
|
||||
"double precision constant requires cl_khr_fp64, casting to single precision">;
|
||||
|
||||
// C99 variable-length arrays
|
||||
def ext_vla : Extension<
|
||||
|
|
|
@ -2601,9 +2601,14 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
|
|||
bool isExact = (result == APFloat::opOK);
|
||||
Res = FloatingLiteral::Create(Context, Val, isExact, Ty, Tok.getLocation());
|
||||
|
||||
if (getLangOptions().SinglePrecisionConstants && Ty == Context.DoubleTy)
|
||||
ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
|
||||
|
||||
if (Ty == Context.DoubleTy) {
|
||||
if (getLangOptions().SinglePrecisionConstants) {
|
||||
ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
|
||||
} else if (getLangOptions().OpenCL && !getOpenCLOptions().cl_khr_fp64) {
|
||||
Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64);
|
||||
ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
|
||||
}
|
||||
}
|
||||
} else if (!Literal.isIntegerLiteral()) {
|
||||
return ExprError();
|
||||
} else {
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
|
||||
|
||||
void f1(double da) { // expected-error {{requires cl_khr_fp64 extension}}
|
||||
double d; // expected-error {{requires cl_khr_fp64 extension}}
|
||||
void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
|
||||
double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
|
||||
(void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
|
||||
}
|
||||
|
||||
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
|
||||
|
||||
void f2(void) {
|
||||
double d;
|
||||
(void) 1.0;
|
||||
}
|
||||
|
||||
#pragma OPENCL EXTENSION cl_khr_fp64 : disable
|
||||
|
||||
void f3(void) {
|
||||
double d; // expected-error {{requires cl_khr_fp64 extension}}
|
||||
double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче