aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 48816d3..3a73cea 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13464,6 +13464,38 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return Success(DidOverflow, E);
}
+ case clang::X86::BI__builtin_ia32_addcarryx_u32:
+ case clang::X86::BI__builtin_ia32_addcarryx_u64:
+ case clang::X86::BI__builtin_ia32_subborrow_u32:
+ case clang::X86::BI__builtin_ia32_subborrow_u64: {
+ LValue ResultLValue;
+ APSInt CarryIn, LHS, RHS;
+ QualType ResultType = E->getArg(3)->getType()->getPointeeType();
+ if (!EvaluateInteger(E->getArg(0), CarryIn, Info) ||
+ !EvaluateInteger(E->getArg(1), LHS, Info) ||
+ !EvaluateInteger(E->getArg(2), RHS, Info) ||
+ !EvaluatePointer(E->getArg(3), ResultLValue, Info))
+ return false;
+
+ bool IsAdd = BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u32 ||
+ BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u64;
+
+ unsigned BitWidth = LHS.getBitWidth();
+ unsigned CarryInBit = CarryIn.ugt(0) ? 1 : 0;
+ APInt ExResult =
+ IsAdd
+ ? (LHS.zext(BitWidth + 1) + (RHS.zext(BitWidth + 1) + CarryInBit))
+ : (LHS.zext(BitWidth + 1) - (RHS.zext(BitWidth + 1) + CarryInBit));
+
+ APInt Result = ExResult.extractBits(BitWidth, 0);
+ uint64_t CarryOut = ExResult.extractBitsAsZExtValue(1, BitWidth);
+
+ APValue APV{APSInt(Result, /*isUnsigned=*/true)};
+ if (!handleAssignment(Info, E, ResultLValue, ResultType, APV))
+ return false;
+ return Success(CarryOut, E);
+ }
+
case clang::X86::BI__builtin_ia32_bextr_u32:
case clang::X86::BI__builtin_ia32_bextr_u64:
case clang::X86::BI__builtin_ia32_bextri_u32: