diff options
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index ce41308344..01c9fe7cd8 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -4306,7 +4306,7 @@ bool IntExprEvaluator::TryEvaluateBuiltinObjectSize(const CallExpr *E) { } bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { - switch (E->isBuiltinCall()) { + switch (unsigned BuiltinOp = E->isBuiltinCall()) { default: return ExprEvaluatorBaseTy::VisitCallExpr(E); @@ -4365,6 +4365,7 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { return Error(E); + case Builtin::BI__atomic_always_lock_free: case Builtin::BI__atomic_is_lock_free: case Builtin::BI__c11_atomic_is_lock_free: { APSInt SizeVal; @@ -4382,32 +4383,31 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { // Check power-of-two. CharUnits Size = CharUnits::fromQuantity(SizeVal.getZExtValue()); - if (!Size.isPowerOfTwo()) -#if 0 - // FIXME: Suppress this folding until the ABI for the promotion width - // settles. - return Success(0, E); -#else - return Error(E); -#endif - -#if 0 - // Check against promotion width. - // FIXME: Suppress this folding until the ABI for the promotion width - // settles. - unsigned PromoteWidthBits = - Info.Ctx.getTargetInfo().getMaxAtomicPromoteWidth(); - if (Size > Info.Ctx.toCharUnitsFromBits(PromoteWidthBits)) - return Success(0, E); -#endif - - // Check against inlining width. - unsigned InlineWidthBits = - Info.Ctx.getTargetInfo().getMaxAtomicInlineWidth(); - if (Size <= Info.Ctx.toCharUnitsFromBits(InlineWidthBits)) - return Success(1, E); + if (Size.isPowerOfTwo()) { + // Check against inlining width. + unsigned InlineWidthBits = + Info.Ctx.getTargetInfo().getMaxAtomicInlineWidth(); + if (Size <= Info.Ctx.toCharUnitsFromBits(InlineWidthBits)) { + if (BuiltinOp == Builtin::BI__c11_atomic_is_lock_free || + Size == CharUnits::One() || + E->getArg(1)->isNullPointerConstant(Info.Ctx, + Expr::NPC_NeverValueDependent)) + // OK, we will inline appropriately-aligned operations of this size, + // and _Atomic(T) is appropriately-aligned. + return Success(1, E); + + QualType PointeeType = E->getArg(1)->IgnoreImpCasts()->getType()-> + castAs<PointerType>()->getPointeeType(); + if (!PointeeType->isIncompleteType() && + Info.Ctx.getTypeAlignInChars(PointeeType) >= Size) { + // OK, we will inline operations on this object. + return Success(1, E); + } + } + } - return Error(E); + return BuiltinOp == Builtin::BI__atomic_always_lock_free ? + Success(0, E) : Error(E); } } } |