[cfe-commits] r69821 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c
Eli Friedman
eli.friedman at gmail.com
Wed Apr 22 12:23:09 PDT 2009
Author: efriedma
Date: Wed Apr 22 14:23:09 2009
New Revision: 69821
URL: http://llvm.org/viewvc/llvm-project?rev=69821&view=rev
Log:
Add handling for complex->int, int->complex float, and float->complex
int. Note that constant int->complex float and float->complex int casts
were being miscompiled.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=69821&r1=69820&r2=69821&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Apr 22 14:23:09 2009
@@ -1205,7 +1205,18 @@
return true;
}
- // FIXME: Handle complex types
+ if (SrcType->isAnyComplexType()) {
+ APValue C;
+ if (!EvaluateComplex(SubExpr, C, Info))
+ return false;
+ if (C.isComplexFloat())
+ return Success(HandleFloatToIntCast(DestType, SrcType,
+ C.getComplexFloatReal(), Info.Ctx),
+ E);
+ else
+ return Success(HandleIntToIntCast(DestType, SrcType,
+ C.getComplexIntReal(), Info.Ctx), E);
+ }
// FIXME: Handle vectors
if (!SrcType->isRealFloatingType())
@@ -1467,28 +1478,41 @@
if (SubType->isRealFloatingType()) {
APFloat Result(0.0);
-
+
if (!EvaluateFloat(SubExpr, Result, Info))
return APValue();
-
- // Apply float conversion if necessary.
- Result = HandleFloatToFloatCast(EltType, SubType, Result, Info.Ctx);
- return APValue(Result,
- APFloat(Result.getSemantics(), APFloat::fcZero, false));
+
+ if (EltType->isRealFloatingType()) {
+ Result = HandleFloatToFloatCast(EltType, SubType, Result, Info.Ctx);
+ return APValue(Result,
+ APFloat(Result.getSemantics(), APFloat::fcZero, false));
+ } else {
+ llvm::APSInt IResult;
+ IResult = HandleFloatToIntCast(EltType, SubType, Result, Info.Ctx);
+ llvm::APSInt Zero(IResult.getBitWidth(), !IResult.isSigned());
+ Zero = 0;
+ return APValue(IResult, Zero);
+ }
} else if (SubType->isIntegerType()) {
APSInt Result;
-
+
if (!EvaluateInteger(SubExpr, Result, Info))
return APValue();
- // Apply integer conversion if necessary.
- Result = HandleIntToIntCast(EltType, SubType, Result, Info.Ctx);
- llvm::APSInt Zero(Result.getBitWidth(), !Result.isSigned());
- Zero = 0;
- return APValue(Result, Zero);
+ if (EltType->isRealFloatingType()) {
+ APFloat FResult =
+ HandleIntToFloatCast(EltType, SubType, Result, Info.Ctx);
+ return APValue(FResult,
+ APFloat(FResult.getSemantics(), APFloat::fcZero, false));
+ } else {
+ Result = HandleIntToIntCast(EltType, SubType, Result, Info.Ctx);
+ llvm::APSInt Zero(Result.getBitWidth(), !Result.isSigned());
+ Zero = 0;
+ return APValue(Result, Zero);
+ }
} else if (const ComplexType *CT = SubType->getAsComplexType()) {
APValue Src;
-
+
if (!EvaluateComplex(SubExpr, Src, Info))
return APValue();
Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=69821&r1=69820&r2=69821&view=diff
==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Wed Apr 22 14:23:09 2009
@@ -61,3 +61,5 @@
struct a { int x, y };
static struct a V2 = (struct a)(struct a){ 1, 2};
static const struct a V1 = (struct a){ 1, 2};
+
+EVAL_EXPR(30, (int)(_Complex float)((1<<30)-1) == (1<<30) ? 1 : -1)
More information about the cfe-commits
mailing list