Skip to content

Commit ea1c659

Browse files
committed
a minor refactoring
1 parent cb94a63 commit ea1c659

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,13 @@ RValue CIRGenFunction::emitRotate(const CallExpr *E, bool IsRotateRight) {
345345
return RValue::get(r);
346346
}
347347

348-
static bool isMemBuiltinOutOfBoundPossible(const CallExpr *expr,
349-
clang::CIRGen::CIRGenModule &cgm,
348+
static bool isMemBuiltinOutOfBoundPossible(const clang::Expr *sizeArg,
349+
const clang::Expr *dstSizeArg,
350+
clang::ASTContext &astContext,
350351
llvm::APSInt &size) {
351352
clang::Expr::EvalResult sizeResult, dstSizeResult;
352-
if (!expr->getArg(2)->EvaluateAsInt(sizeResult, cgm.getASTContext()) ||
353-
!expr->getArg(3)->EvaluateAsInt(dstSizeResult, cgm.getASTContext()))
353+
if (!sizeArg->EvaluateAsInt(sizeResult, astContext) ||
354+
!dstSizeArg->EvaluateAsInt(dstSizeResult, astContext))
354355
return true;
355356
size = sizeResult.Val.getInt();
356357
llvm::APSInt dstSize = dstSizeResult.Val.getInt();
@@ -1501,7 +1502,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
15011502
case Builtin::BI__builtin___memcpy_chk: {
15021503
// fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2.
15031504
llvm::APSInt size;
1504-
if (isMemBuiltinOutOfBoundPossible(E, CGM, size))
1505+
if (isMemBuiltinOutOfBoundPossible(E->getArg(2), E->getArg(3),
1506+
CGM.getASTContext(), size))
15051507
break;
15061508
Address dest = emitPointerWithAlignment(E->getArg(0));
15071509
Address src = emitPointerWithAlignment(E->getArg(1));
@@ -1517,7 +1519,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
15171519
case Builtin::BI__builtin___memmove_chk: {
15181520
// fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2.
15191521
llvm::APSInt size;
1520-
if (isMemBuiltinOutOfBoundPossible(E, CGM, size))
1522+
if (isMemBuiltinOutOfBoundPossible(E->getArg(2), E->getArg(3),
1523+
CGM.getASTContext(), size))
15211524
break;
15221525
Address Dest = emitPointerWithAlignment(E->getArg(0));
15231526
Address Src = emitPointerWithAlignment(E->getArg(1));
@@ -1556,7 +1559,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
15561559
case Builtin::BI__builtin___memset_chk: {
15571560
// fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.
15581561
llvm::APSInt size;
1559-
if (isMemBuiltinOutOfBoundPossible(E, CGM, size))
1562+
if (isMemBuiltinOutOfBoundPossible(E->getArg(2), E->getArg(3),
1563+
CGM.getASTContext(), size))
15601564
break;
15611565
Address dest = emitPointerWithAlignment(E->getArg(0));
15621566
mlir::Value byteVal = emitScalarExpr(E->getArg(1));

0 commit comments

Comments
 (0)