]> granicus.if.org Git - clang/commitdiff
Fix UnitTests/2004-02-02-NegativeZero.c, which regressed when
authorChris Lattner <sabre@nondot.org>
Mon, 28 Jun 2010 17:12:37 +0000 (17:12 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 28 Jun 2010 17:12:37 +0000 (17:12 +0000)
I broke negate of FP values.

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

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/exprs.c

index d0d89c66a475927bbaa2b027b32aac8e13768801..e2b4d2dd1552d3051317e9218d66a548a795d00e 100644 (file)
@@ -1224,8 +1224,12 @@ Value *ScalarExprEmitter::VisitUnaryMinus(const UnaryOperator *E) {
   TestAndClearIgnoreResultAssign();
   // Emit unary minus with EmitSub so we handle overflow cases etc.
   BinOpInfo BinOp;
-  BinOp.RHS = Visit(E->getSubExpr());;
-  BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
+  BinOp.RHS = Visit(E->getSubExpr());
+  
+  if (BinOp.RHS->getType()->isFPOrFPVectorTy())
+    BinOp.LHS = llvm::ConstantFP::getZeroValueForNegation(BinOp.RHS->getType());
+  else 
+    BinOp.LHS = llvm::Constant::getNullValue(BinOp.RHS->getType());
   BinOp.Ty = E->getType();
   BinOp.Opcode = BinaryOperator::Sub;
   BinOp.E = E;
index b3cf9133bdac1f43e639f7cae6826076d299212c..f7b02bc8a0975176143c34823defc648cf42c849 100644 (file)
@@ -137,3 +137,10 @@ int f12() {
   // CHECK: ret i32 1
   return 1||1;
 }
+
+// Make sure negate of fp uses -0.0 for proper -0 handling.
+double f13(double X) {
+  // CHECK: define double @f13
+  // CHECK: fsub double -0.000000e+00, %tmp
+  return -X;
+}