Fix invalid evaluation of _Complex float (real & imaginary parts had
mismatched semantics).
- Enforce this in APValue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62924 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index f45bd78..16c6e89 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -1194,7 +1194,8 @@
if (!EvaluateFloat(E->getSubExpr(), Result, Info))
return APValue();
- return APValue(APFloat(0.0), Result);
+ return APValue(APFloat(Result.getSemantics(), APFloat::fcZero),
+ Result);
}
APValue VisitCastExpr(CastExpr *E) {
@@ -1206,7 +1207,8 @@
if (!EvaluateFloat(SubExpr, Result, Info))
return APValue();
- return APValue(Result, APFloat(0.0));
+ return APValue(Result,
+ APFloat(Result.getSemantics(), APFloat::fcZero));
}
// FIXME: Handle more casts.
@@ -1221,6 +1223,10 @@
static bool EvaluateComplexFloat(const Expr *E, APValue &Result, EvalInfo &Info)
{
Result = ComplexFloatExprEvaluator(Info).Visit(const_cast<Expr*>(E));
+ if (Result.isComplexFloat())
+ assert(&Result.getComplexFloatReal().getSemantics() ==
+ &Result.getComplexFloatImag().getSemantics() &&
+ "Invalid complex evaluation.");
return Result.isComplexFloat();
}