Skip to content

Commit f16035e

Browse files
Replace else-if with type switch
1 parent 51a4da2 commit f16035e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,15 +2318,20 @@ mlir::LogicalResult CIRToLLVMGetBitfieldOpLowering::matchAndRewrite(
23182318
mlir::MLIRContext *context = storageType.getContext();
23192319
unsigned storageSize = 0;
23202320

2321-
if (auto arTy = mlir::dyn_cast<cir::ArrayType>(storageType))
2322-
storageSize = arTy.getSize() * 8;
2323-
else if (auto intTy = mlir::dyn_cast<cir::IntType>(storageType))
2324-
storageSize = intTy.getWidth();
2325-
else
2326-
llvm_unreachable(
2327-
"Either ArrayType or IntType expected for bitfields storage");
2328-
2329-
mlir::IntegerType intType = mlir::IntegerType::get(context, storageSize);
2321+
mlir::IntegerType intType =
2322+
TypeSwitch<mlir::Type, mlir::IntegerType>(storageType)
2323+
.Case<cir::ArrayType>([&](cir::ArrayType atTy) {
2324+
storageSize = atTy.getSize() * 8;
2325+
return mlir::IntegerType::get(context, storageSize);
2326+
})
2327+
.Case<cir::IntType>([&](cir::IntType intTy) {
2328+
storageSize = intTy.getWidth();
2329+
return mlir::IntegerType::get(context, storageSize);
2330+
})
2331+
.Default([](mlir::Type) -> mlir::IntegerType {
2332+
llvm_unreachable(
2333+
"Either ArrayType or IntType expected for bitfields storage");
2334+
});
23302335

23312336
mlir::Value val = rewriter.create<mlir::LLVM::LoadOp>(
23322337
op.getLoc(), intType, adaptor.getAddr(), 0, op.getIsVolatile());

0 commit comments

Comments
 (0)