diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1330,6 +1330,22 @@ } } + if (SrcType->isFloatingType() && DstType->isFloatingType()) { + // Handle cast between PPC double-double and IEEE 128-bit float types. + const auto *SrcSemantics = &CGF.getContext().getFloatTypeSemantics(SrcType); + const auto *DstSemantics = &CGF.getContext().getFloatTypeSemantics(DstType); + if (SrcSemantics == &llvm::APFloat::PPCDoubleDouble() && + DstSemantics == &llvm::APFloat::IEEEquad()) + return Builder.CreateCall( + CGF.CGM.getIntrinsic(llvm::Intrinsic::ppc_convert_ppcf128_to_f128), + Src); + if (SrcSemantics == &llvm::APFloat::IEEEquad() && + DstSemantics == &llvm::APFloat::PPCDoubleDouble()) + return Builder.CreateCall( + CGF.CGM.getIntrinsic(llvm::Intrinsic::ppc_convert_f128_to_ppcf128), + Src); + } + // Ignore conversions like int -> uint. if (SrcTy == DstTy) { if (Opts.EmitImplicitIntegerSignChangeChecks) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1537,8 +1537,9 @@ // At this point, we have two different arithmetic types. // Diagnose attempts to convert between __ibm128, __float128 and long double - // where such conversions currently can't be handled. - if (unsupportedTypeConversion(*this, LHSType, RHSType)) + // in arithmetic or comparison. + if (unsupportedTypeConversion(*this, LHSType, RHSType) && + ACK != ACK_Conditional && ACK != ACK_CompAssign) return QualType(); // Handle complex types first (C99 6.3.1.8p1). @@ -8369,15 +8370,6 @@ QualType LHSTy = LHS.get()->getType(); QualType RHSTy = RHS.get()->getType(); - // Diagnose attempts to convert between __ibm128, __float128 and long double - // where such conversions currently can't be handled. - if (unsupportedTypeConversion(*this, LHSTy, RHSTy)) { - Diag(QuestionLoc, - diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); - return QualType(); - } - // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary // selection operator (?:). if (getLangOpts().OpenCL && @@ -9304,11 +9296,6 @@ return Incompatible; } - // Diagnose attempts to convert between __ibm128, __float128 and long double - // where such conversions currently can't be handled. - if (unsupportedTypeConversion(*this, LHSType, RHSType)) - return Incompatible; - // Disallow assigning a _Complex to a real type in C++ mode since it simply // discards the imaginary part. if (getLangOpts().CPlusPlus && RHSType->getAs() && diff --git a/clang/test/CodeGen/ibm128-cast.c b/clang/test/CodeGen/ibm128-cast.c --- a/clang/test/CodeGen/ibm128-cast.c +++ b/clang/test/CodeGen/ibm128-cast.c @@ -2,11 +2,18 @@ // RUN: -target-feature +float128 -mabi=ieeelongdouble -fsyntax-only -Wno-unused %s // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown -verify \ // RUN: -target-feature +float128 -fsyntax-only -Wno-unused %s +// RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown -DCODEGEN \ +// RUN: -target-feature +float128 -mabi=ieeelongdouble %s -o - | FileCheck %s -__float128 cast1(__ibm128 x) { return x; } // expected-error {{returning '__ibm128' from a function with incompatible result type '__float128'}} +// CHECK: define dso_local fp128 @cast1(ppc_fp128 %{{.+}}) +// CHECK: %{{.+}} = call fp128 @llvm.ppc.convert.ppcf128.to.f128(ppc_fp128 %{{.+}}) +__float128 cast1(__ibm128 x) { return x; } // expected-no-error -__ibm128 cast2(__float128 x) { return x; } // expected-error {{returning '__float128' from a function with incompatible result type '__ibm128'}} +// IEEE: define dso_local ppc_fp128 @cast2(fp128 %{{.+}}) +// IEEE: %{{.+}} = call ppc_fp128 @llvm.ppc.convert.f128.to.ppcf128(fp128 %{{.+}}) +__ibm128 cast2(__float128 x) { return x; } // expected-no-error +#ifndef CODEGEN __ibm128 gf; void narrow(double *d, float *f) { @@ -17,9 +24,9 @@ } #ifdef __LONG_DOUBLE_IEEE128__ -long double cast3(__ibm128 x) { return x; } // expected-error {{returning '__ibm128' from a function with incompatible result type 'long double'}} +long double cast3(__ibm128 x) { return x; } // expected-no-error -__ibm128 cast4(long double x) { return x; } // expected-error {{returning 'long double' from a function with incompatible result type '__ibm128'}} +__ibm128 cast4(long double x) { return x; } // expected-no-error void imp_cast(__ibm128 w, __float128 q, long double l, _Bool b) { w + q; // expected-error {{invalid operands to binary expression ('__ibm128' and '__float128')}} @@ -30,12 +37,12 @@ q *w; // expected-error {{invalid operands to binary expression ('__float128' and '__ibm128')}} q / w; // expected-error {{invalid operands to binary expression ('__float128' and '__ibm128')}} w / l; // expected-error {{invalid operands to binary expression ('__ibm128' and 'long double')}} - w = q; // expected-error {{assigning to '__ibm128' from incompatible type '__float128'}} - q = w; // expected-error {{assigning to '__float128' from incompatible type '__ibm128'}} - l = w; // expected-error {{assigning to 'long double' from incompatible type '__ibm128'}} - w = l; // expected-error {{assigning to '__ibm128' from incompatible type 'long double'}} - b ? q : w; // expected-error {{incompatible operand types ('__float128' and '__ibm128')}} - !b ? w : l; // expected-error {{incompatible operand types ('__ibm128' and 'long double')}} + w = q; // expected-no-error {{assigning to '__ibm128' from incompatible type '__float128'}} + q = w; // expected-no-error {{assigning to '__float128' from incompatible type '__ibm128'}} + l = w; // expected-no-error {{assigning to 'long double' from incompatible type '__ibm128'}} + w = l; // expected-no-error {{assigning to '__ibm128' from incompatible type 'long double'}} + b ? q : w; // expected-no-error {{incompatible operand types ('__float128' and '__ibm128')}} + !b ? w : l; // expected-no-error {{incompatible operand types ('__ibm128' and 'long double')}} } #elif __LONG_DOUBLE_IBM128__ long double cast3(__ibm128 x) { return x; } // expected-no-error {{returning '__ibm128' from a function with incompatible result type 'long double'}} @@ -51,11 +58,12 @@ q *w; // expected-error {{invalid operands to binary expression ('__float128' and '__ibm128')}} q / w; // expected-error {{invalid operands to binary expression ('__float128' and '__ibm128')}} w / l; // expected-no-error {{invalid operands to binary expression ('__ibm128' and 'long double')}} - w = q; // expected-error {{assigning to '__ibm128' from incompatible type '__float128'}} - q = w; // expected-error {{assigning to '__float128' from incompatible type '__ibm128'}} + w = q; // expected-no-error {{assigning to '__ibm128' from incompatible type '__float128'}} + q = w; // expected-no-error {{assigning to '__float128' from incompatible type '__ibm128'}} l = w; // expected-no-error {{assigning to 'long double' from incompatible type '__ibm128'}} w = l; // expected-no-error {{assigning to '__ibm128' from incompatible type 'long double'}} - b ? q : w; // expected-error {{incompatible operand types ('__float128' and '__ibm128')}} + b ? q : w; // expected-no-error {{incompatible operand types ('__float128' and '__ibm128')}} !b ? w : l; // expected-no-error {{incompatible operand types ('__ibm128' and 'long double')}} } #endif +#endif diff --git a/clang/test/Sema/float128-ld-incompatibility.cpp b/clang/test/Sema/float128-ld-incompatibility.cpp --- a/clang/test/Sema/float128-ld-incompatibility.cpp +++ b/clang/test/Sema/float128-ld-incompatibility.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \ // RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr9 \ -// RUN: -target-feature +float128 %s +// RUN: -Wno-unused-value -Wno-parentheses -target-feature +float128 %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -Wno-parentheses %s __float128 qf(); @@ -35,5 +35,5 @@ q / ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} ld = q; // expected-error {{assigning to 'long double' from incompatible type '__float128'}} q = ld; // expected-error {{assigning to '__float128' from incompatible type 'long double'}} - q + b ? q : ld; // expected-error {{incompatible operand types ('__float128' and 'long double')}} + q + b ? q : ld; // expected-no-error }