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

Eli Friedman eli.friedman at gmail.com
Fri Feb 27 19:59:07 PST 2009


Author: efriedma
Date: Fri Feb 27 21:59:05 2009
New Revision: 65677

URL: http://llvm.org/viewvc/llvm-project?rev=65677&view=rev
Log:
Fix obvious shortcoming in the implementations of Evaluate for 
integer __real__ and __imag__.  Not sure how I missed this.


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=65677&r1=65676&r2=65677&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Feb 27 21:59:05 2009
@@ -645,9 +645,7 @@
   }
 
   bool VisitChooseExpr(const ChooseExpr *E);
-  bool VisitUnaryReal(const UnaryOperator *E) {
-    return Visit(E->getSubExpr());
-  }
+  bool VisitUnaryReal(const UnaryOperator *E);
   bool VisitUnaryImag(const UnaryOperator *E);
 
 private:
@@ -1192,7 +1190,25 @@
   return Visit(EvalExpr);
 }
 
+bool IntExprEvaluator::VisitUnaryReal(const UnaryOperator *E) {
+  if (E->getSubExpr()->getType()->isAnyComplexType()) {
+    APValue LV;
+    if (!EvaluateComplex(E->getSubExpr(), LV, Info) || !LV.isComplexInt())
+      return Error(E->getExprLoc(), diag::note_invalid_subexpr_in_ice, E);
+    return Success(LV.getComplexIntReal(), E);
+  }
+
+  return Visit(E->getSubExpr());
+}
+
 bool IntExprEvaluator::VisitUnaryImag(const UnaryOperator *E) {
+  if (E->getSubExpr()->getType()->isComplexIntegerType()) {
+    APValue LV;
+    if (!EvaluateComplex(E->getSubExpr(), LV, Info) || !LV.isComplexInt())
+      return Error(E->getExprLoc(), diag::note_invalid_subexpr_in_ice, E);
+    return Success(LV.getComplexIntImag(), E);
+  }
+
   if (!E->getSubExpr()->isEvaluatable(Info.Ctx))
     Info.EvalResult.HasSideEffects = true;
   return Success(0, E);

Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=65677&r1=65676&r2=65677&view=diff

==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Fri Feb 27 21:59:05 2009
@@ -42,3 +42,8 @@
 EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
 
 EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));
+
+EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
+
+EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
+





More information about the cfe-commits mailing list