summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-10-12 00:18:19 +0000
committerTed Kremenek <kremenek@apple.com>2012-10-12 00:18:19 +0000
commit6fdefb549595254e795feb6f7749a8b8b9dff47c (patch)
treeaaadaaa40a4a10b45de207c7190168443c97d123 /clang/lib
parentcfa46a82b8f74564522a493b9ae3e715d83d06a4 (diff)
downloadbcm5719-llvm-6fdefb549595254e795feb6f7749a8b8b9dff47c.tar.gz
bcm5719-llvm-6fdefb549595254e795feb6f7749a8b8b9dff47c.zip
Conditionally use an integral cast for BodyFarm support for OSAtomicCompareAndSwap if the return type is not a boolean.
llvm-svn: 165774
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/BodyFarm.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp
index 9a04a826751..794ff9cc2bb 100644
--- a/clang/lib/Analysis/BodyFarm.cpp
+++ b/clang/lib/Analysis/BodyFarm.cpp
@@ -64,7 +64,7 @@ public:
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 @@ ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) {
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 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D)
// }
// 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 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D)
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 =
OpenPOWER on IntegriCloud