[cfe-commits] r111080 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c

Eli Friedman eli.friedman at gmail.com
Sat Aug 14 13:52:13 PDT 2010


Author: efriedma
Date: Sat Aug 14 15:52:13 2010
New Revision: 111080

URL: http://llvm.org/viewvc/llvm-project?rev=111080&view=rev
Log:
PR7884: Fix the implementations of __real__ and __imag__ on real floats.


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=111080&r1=111079&r2=111080&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Aug 14 15:52:13 2010
@@ -1842,18 +1842,30 @@
 }
 
 bool FloatExprEvaluator::VisitUnaryReal(const UnaryOperator *E) {
-  ComplexValue CV;
-  if (!EvaluateComplex(E->getSubExpr(), CV, Info))
-    return false;
-  Result = CV.FloatReal;
-  return true;
+  if (E->getSubExpr()->getType()->isAnyComplexType()) {
+    ComplexValue CV;
+    if (!EvaluateComplex(E->getSubExpr(), CV, Info))
+      return false;
+    Result = CV.FloatReal;
+    return true;
+  }
+
+  return Visit(E->getSubExpr());
 }
 
 bool FloatExprEvaluator::VisitUnaryImag(const UnaryOperator *E) {
-  ComplexValue CV;
-  if (!EvaluateComplex(E->getSubExpr(), CV, Info))
-    return false;
-  Result = CV.FloatImag;
+  if (E->getSubExpr()->getType()->isAnyComplexType()) {
+    ComplexValue CV;
+    if (!EvaluateComplex(E->getSubExpr(), CV, Info))
+      return false;
+    Result = CV.FloatImag;
+    return true;
+  }
+
+  if (!E->getSubExpr()->isEvaluatable(Info.Ctx))
+    Info.EvalResult.HasSideEffects = true;
+  const llvm::fltSemantics &Sem = Info.Ctx.getFloatTypeSemantics(E->getType());
+  Result = llvm::APFloat::getZero(Sem);
   return true;
 }
 

Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=111080&r1=111079&r2=111080&view=diff
==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Sat Aug 14 15:52:13 2010
@@ -74,5 +74,9 @@
 EVAL_EXPR(35, constbool)
 EVAL_EXPR(36, constbool)
 
-EVAL_EXPR(37, (1,2.0) == 2.0)
-EVAL_EXPR(38, __builtin_expect(1,1) == 1)
+EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
+EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
+
+// PR7884
+EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
+EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)





More information about the cfe-commits mailing list