Skip to content

Commit 073ace9

Browse files
committed
Address review feedback
1 parent 4121aec commit 073ace9

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
157157
mlir::Value size = emitScalarExpr(e->getArg(0));
158158

159159
// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
160-
const TargetInfo &TI = getContext().getTargetInfo();
161-
const CharUnits SuitableAlignmentInBytes =
162-
getContext().toCharUnitsFromBits(TI.getSuitableAlign());
160+
const TargetInfo &ti = getContext().getTargetInfo();
161+
const CharUnits suitableAlignmentInBytes =
162+
getContext().toCharUnitsFromBits(ti.getSuitableAlign());
163163

164164
// Emit the alloca op with type `u8 *` to match the semantics of
165165
// `llvm.alloca`. We later bitcast the type to `void *` to match the
166166
// semantics of C/C++
167167
// FIXME(cir): It may make sense to allow AllocaOp of type `u8` to return a
168168
// pointer of type `void *`. This will require a change to the allocaOp
169169
// verifier.
170-
auto allocaAddr = builder.createAlloca(
170+
mlir::Value allocaAddr = builder.createAlloca(
171171
getLoc(e->getSourceRange()), builder.getUInt8PtrTy(),
172-
builder.getUInt8Ty(), "bi_alloca", SuitableAlignmentInBytes, size);
172+
builder.getUInt8Ty(), "bi_alloca", suitableAlignmentInBytes, size);
173173

174174
// Initialize the allocated buffer if required.
175175
if (builtinID != Builtin::BI__builtin_alloca_uninitialized) {

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,11 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
10541054
cir::AllocaOp op, OpAdaptor adaptor,
10551055
mlir::ConversionPatternRewriter &rewriter) const {
10561056
mlir::Value size =
1057-
op.isDynamic() ? adaptor.getDynAllocSize()
1058-
: rewriter.create<mlir::LLVM::ConstantOp>(
1059-
op.getLoc(),
1060-
typeConverter->convertType(rewriter.getIndexType()),
1061-
rewriter.getIntegerAttr(rewriter.getIndexType(), 1));
1057+
op.isDynamic()
1058+
? adaptor.getDynAllocSize()
1059+
: rewriter.create<mlir::LLVM::ConstantOp>(
1060+
op.getLoc(),
1061+
typeConverter->convertType(rewriter.getIndexType()), 1);
10621062
mlir::Type elementTy =
10631063
convertTypeForMemory(*getTypeConverter(), dataLayout, op.getAllocaType());
10641064
mlir::Type resultTy =

clang/test/CIR/CodeGen/builtin_call.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ void unreachable() {
211211
// LLVM: unreachable
212212
// LLVM: }
213213

214+
// OGCG-LABEL: @_Z11unreachablev
215+
// OGCG: unreachable
216+
// OGCG: }
217+
214218
void f1();
215219
void unreachable2() {
216220
__builtin_unreachable();
@@ -229,6 +233,9 @@ void unreachable2() {
229233
// LLVM-NEXT: call void @_Z2f1v()
230234
// LLVM: }
231235

236+
// OGCG-LABEL: @_Z12unreachable2v
237+
// OGCG: unreachable
238+
232239
void trap() {
233240
__builtin_trap();
234241
}
@@ -241,6 +248,10 @@ void trap() {
241248
// LLVM: call void @llvm.trap()
242249
// LLVM: }
243250

251+
// OGCG-LABEL: @_Z4trapv
252+
// OGCG: call void @llvm.trap()
253+
// OGCG: }
254+
244255
void trap2() {
245256
__builtin_trap();
246257
f1();
@@ -259,6 +270,12 @@ void trap2() {
259270
// LLVM-NEXT: call void @_Z2f1v()
260271
// LLVM: }
261272

273+
// OGCG-LABEL: define{{.*}} void @_Z5trap2v
274+
// OGCG: call void @llvm.trap()
275+
// OGCG-NEXT: call void @_Z2f1v()
276+
// OGCG: ret void
277+
// OGCG: }
278+
262279
void *test_alloca(unsigned long n) {
263280
return __builtin_alloca(n);
264281
}
@@ -268,3 +285,24 @@ void *test_alloca(unsigned long n) {
268285

269286
// LLVM-LABEL: @_Z11test_allocam(
270287
// LLVM: alloca i8, i64 %{{.+}}
288+
289+
// OGCG-LABEL: @_Z11test_allocam(
290+
// OGCG: alloca i8, i64 %{{.+}}
291+
292+
bool test_multiple_allocas(unsigned long n) {
293+
void *a = __builtin_alloca(n);
294+
void *b = __builtin_alloca(n);
295+
return a != b;
296+
}
297+
298+
// CIR-LABEL: @_Z21test_multiple_allocasm(
299+
// CIR: %{{.+}} = cir.alloca !u8i, !cir.ptr<!u8i>, %{{.+}} : !u64i, ["bi_alloca"]
300+
// CIR: %{{.+}} = cir.alloca !u8i, !cir.ptr<!u8i>, %{{.+}} : !u64i, ["bi_alloca"]
301+
302+
// LLVM-LABEL: @_Z21test_multiple_allocasm(
303+
// LLVM: alloca i8, i64 %{{.+}}
304+
// LLVM: alloca i8, i64 %{{.+}}
305+
306+
// OGCG-LABEL: @_Z21test_multiple_allocasm(
307+
// OGCG: alloca i8, i64 %{{.+}}
308+
// OGCG: alloca i8, i64 %{{.+}}

0 commit comments

Comments
 (0)