[cfe-commits] r165774 - /cfe/trunk/lib/Analysis/BodyFarm.cpp

Ted Kremenek kremenek at apple.com
Thu Oct 11 17:18:19 PDT 2012


Author: kremenek
Date: Thu Oct 11 19:18:19 2012
New Revision: 165774

URL: http://llvm.org/viewvc/llvm-project?rev=165774&view=rev
Log:
Conditionally use an integral cast for BodyFarm support for OSAtomicCompareAndSwap if the return type is not a boolean.

Modified:
    cfe/trunk/lib/Analysis/BodyFarm.cpp

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=165774&r1=165773&r2=165774&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Thu Oct 11 19:18:19 2012
@@ -64,7 +64,7 @@
   UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
   
   /// Create an implicit cast for an integer conversion.
-  ImplicitCastExpr *makeIntegralCast(const Expr *Arg, QualType Ty);
+  Expr *makeIntegralCast(const Expr *Arg, QualType Ty);
   
   /// Create an implicit cast to a builtin boolean type.
   ImplicitCastExpr *makeIntegralCastToBoolean(const Expr *Arg);
@@ -131,7 +131,10 @@
                                   const_cast<Expr*>(Arg), 0, VK_RValue);
 }
 
-ImplicitCastExpr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
+Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
+  if (Arg->getType() == Ty)
+    return const_cast<Expr*>(Arg);
+  
   return ImplicitCastExpr::Create(C, Ty, CK_IntegralCast,
                                   const_cast<Expr*>(Arg), 0, VK_RValue);
 }
@@ -274,6 +277,11 @@
   //   }
   //   else return NO;
   
+  QualType ResultTy = D->getResultType();
+  bool isBoolean = ResultTy->isBooleanType();
+  if (!isBoolean && !ResultTy->isIntegralType(C))
+    return 0;
+  
   const ParmVarDecl *OldValue = D->getParamDecl(0);
   QualType OldValueTy = OldValue->getType();
 
@@ -310,13 +318,18 @@
         PointeeTy),
       M.makeLvalueToRvalue(M.makeDeclRefExpr(NewValue), NewValueTy),
       NewValueTy);
-  Stmts[1] =
-    M.makeReturn(M.makeIntegralCastToBoolean(M.makeObjCBool(true)));
+  
+  Expr *BoolVal = M.makeObjCBool(true);
+  Expr *RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal)
+                           : M.makeIntegralCast(BoolVal, ResultTy);
+  Stmts[1] = M.makeReturn(RetVal);
   CompoundStmt *Body = M.makeCompound(ArrayRef<Stmt*>(Stmts, 2));
   
   // Construct the else clause.
-  Stmt *Else =
-    M.makeReturn(M.makeIntegralCastToBoolean(M.makeObjCBool(false)));
+  BoolVal = M.makeObjCBool(false);
+  RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal)
+                     : M.makeIntegralCast(BoolVal, ResultTy);
+  Stmt *Else = M.makeReturn(RetVal);
   
   /// Construct the If.
   Stmt *If =





More information about the cfe-commits mailing list