]> granicus.if.org Git - clang/commitdiff
Fix obvious shortcoming in the implementations of Evaluate for
authorEli Friedman <eli.friedman@gmail.com>
Sat, 28 Feb 2009 03:59:05 +0000 (03:59 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 28 Feb 2009 03:59:05 +0000 (03:59 +0000)
integer __real__ and __imag__.  Not sure how I missed this.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65677 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index 68818dbf7b2a83e73c94fbe231cec9fdc2a1c4ae..86a7e8217f73821ba1a121aa1821b32807232a35 100644 (file)
@@ -645,9 +645,7 @@ public:
   }
 
   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 @@ bool IntExprEvaluator::VisitChooseExpr(const ChooseExpr *E) {
   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);
index aebcb6a3fd8ac6ad662bad4b3bbfa4d892d40ae6..fd7b40ea1bab7f3b5022d2dfb2afabb0f23f7f67 100644 (file)
@@ -42,3 +42,8 @@ struct s {
 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);
+