llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clangir Author: Akimasa Watanuki (Men-cotton) <details> <summary>Changes</summary> Fixed a crash in `CIRToLLVMAllocaOpLowering` where `cir.alloca` operations without an explicit alignment attribute failed. The alignment now defaults to 0 if the attribute is missing. Added a regression test in `clang/test/CIR/Lowering/alloca.cir`. --- Full diff: https://github.com/llvm/llvm-project/pull/172663.diff 2 Files Affected: - (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+5-2) - (added) clang/test/CIR/Lowering/alloca.cir (+13) ``````````diff diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 7d854997848aa..82e556f6e65db 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -1515,8 +1515,11 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite( assert(!cir::MissingFeatures::addressSpace()); assert(!cir::MissingFeatures::opAllocaAnnotations()); - rewriter.replaceOpWithNewOp<mlir::LLVM::AllocaOp>( - op, resultTy, elementTy, size, op.getAlignmentAttr().getInt()); + unsigned alignment = 0; + if (auto alignAttr = op.getAlignmentAttr()) + alignment = alignAttr.getInt(); + rewriter.replaceOpWithNewOp<mlir::LLVM::AllocaOp>(op, resultTy, elementTy, + size, alignment); return mlir::success(); } diff --git a/clang/test/CIR/Lowering/alloca.cir b/clang/test/CIR/Lowering/alloca.cir new file mode 100644 index 0000000000000..51980d393eb6f --- /dev/null +++ b/clang/test/CIR/Lowering/alloca.cir @@ -0,0 +1,13 @@ +// RUN: cir-opt %s --cir-to-llvm | FileCheck %s + +!s32i = !cir.int<s, 32> + +module { + // CHECK-LABEL: llvm.func @alloca_no_align + // CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i64) : i64 + // CHECK-NEXT: %{{.*}} = llvm.alloca %[[SIZE]] x i32 : (i64) -> !llvm.ptr + cir.func @alloca_no_align() { + %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["var_name"] + cir.return + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/172663 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
