diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5808,7 +5808,7 @@ << OrigArg->getType() << OrigArg->getSourceRange(); // If this is an implicit conversion from float -> float, double, or - // long double, remove it. + // long double, or half -> half, float, double, or long double, remove it. if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) { // Only remove standard FloatCasts, leaving other casts inplace if (Cast->getCastKind() == CK_FloatingCast) { @@ -5823,6 +5823,18 @@ Cast->setSubExpr(nullptr); TheCall->setArg(NumArgs-1, CastArg); } + + if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Half)) { + assert( + (Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || + Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || + Cast->getType()->isSpecificBuiltinType(BuiltinType::Half) || + Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && + "promotion from half to either half, float, double, or long double " + "is the only expected cast here"); + Cast->setSubExpr(nullptr); + TheCall->setArg(NumArgs-1, CastArg); + } } }