Skip to content

Commit a58760a

Browse files
committed
Address code review comments
1 parent e279be0 commit a58760a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
23532353

23542354
// For sizeof and __datasizeof, we need to scale the number of elements
23552355
// by the size of the array element type.
2356-
auto vlaSize = cgf.getVLASize(vat);
2356+
CIRGenFunction::VlaSizePair vlaSize = cgf.getVLASize(vat);
23572357
mlir::Value numElts = vlaSize.numElts;
23582358

23592359
// Scale the number of non-VLA elements by the non-VLA element size.
@@ -2363,7 +2363,8 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
23632363
mlir::Value eltSizeValue =
23642364
builder.getConstAPInt(numElts.getLoc(), numElts.getType(),
23652365
cgf.cgm.getSize(eltSize).getValue());
2366-
return builder.createMul(loc, eltSizeValue, numElts);
2366+
return builder.createMul(loc, eltSizeValue, numElts,
2367+
cir::OverflowBehavior::NoUnsignedWrap);
23672368
}
23682369

23692370
return numElts;

clang/test/CIR/CodeGen/size-of-vla.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ void vla_type_with_element_type_int() {
4040
// CIR: cir.store {{.*}} %[[CONST_10]], %[[N_ADDR]] : !u64i, !cir.ptr<!u64i>
4141
// CIR: %3 = cir.load {{.*}} %[[N_ADDR]] : !cir.ptr<!u64i>, !u64i
4242
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !u64i
43-
// CIR: %[[SIZE:.*]] = cir.binop(mul, %[[CONST_4]], %3) : !u64i
43+
// CIR: %[[SIZE:.*]] = cir.binop(mul, %[[CONST_4]], %3) nuw : !u64i
4444
// CIR: cir.store {{.*}} %[[SIZE]], %[[SIZE_ADDR]] : !u64i, !cir.ptr<!u64i>
4545

4646
// LLVM: %[[N_ADDR:.*]] = alloca i64, i64 1, align 8
4747
// LLVM: %[[SIZE_ADDR:.*]] = alloca i64, i64 1, align 8
4848
// LLVM: store i64 10, ptr %[[N_ADDR]], align 8
4949
// LLVM: %[[TMP_N:.*]] = load i64, ptr %[[N_ADDR]], align 8
50-
// LLVM: %[[SIZE:.*]] = mul i64 4, %[[TMP_N]]
50+
// LLVM: %[[SIZE:.*]] = mul nuw i64 4, %[[TMP_N]]
5151
// LLVM: store i64 %[[SIZE]], ptr %[[SIZE_ADDR]], align 8
5252

5353
// OGCG: %[[N_ADDR:.*]] = alloca i64, align 8
@@ -120,7 +120,7 @@ void vla_expr_element_type_int() {
120120
// CIR: %[[ARR_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, %[[TMP_N]] : !u64i, ["arr"]
121121
// CIR: %[[SIZE_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["size", init]
122122
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !u64i
123-
// CIR: %[[SIZE:.*]] = cir.binop(mul, %[[CONST_4]], %[[TMP_N]]) : !u64i
123+
// CIR: %[[SIZE:.*]] = cir.binop(mul, %[[CONST_4]], %[[TMP_N]]) nuw : !u64i
124124
// CIR: cir.store {{.*}} %[[SIZE]], %[[SIZE_ADDR]] : !u64i, !cir.ptr<!u64i>
125125
// CIR: %[[TMP_SAVED_STACK:.*]] = cir.load {{.*}} %[[SAVED_STACK_ADDR]] : !cir.ptr<!cir.ptr<!u8i>>, !cir.ptr<!u8i>
126126
// CIR: cir.stackrestore %[[TMP_SAVED_STACK]] : !cir.ptr<!u8i>
@@ -133,7 +133,7 @@ void vla_expr_element_type_int() {
133133
// LLVM: store ptr %[[STACK_SAVE]], ptr %[[SAVED_STACK_ADDR]], align 8
134134
// LLVM: %[[ARR_ADDR:.*]] = alloca i32, i64 %[[TMP_N]], align 16
135135
// LLVM: %[[SIZE_ADDR:.*]] = alloca i64, i64 1, align 8
136-
// LLVM: %[[SIZE:.*]] = mul i64 4, %[[TMP_N]]
136+
// LLVM: %[[SIZE:.*]] = mul nuw i64 4, %[[TMP_N]]
137137
// LLVM: store i64 %[[SIZE]], ptr %[[SIZE_ADDR]], align 8
138138
// LLVM: %[[TMP_SAVED_STACK:.*]] = load ptr, ptr %[[SAVED_STACK_ADDR]], align 8
139139
// LLVM: call void @llvm.stackrestore.p0(ptr %[[TMP_SAVED_STACK]])

0 commit comments

Comments
 (0)