Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][Lowering] fixes return value for = operator for bitfields #1247

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3576,9 +3576,6 @@ mlir::LogicalResult CIRToLLVMSetBitfieldOpLowering::matchAndRewrite(

auto resultTy = getTypeConverter()->convertType(op.getType());

resultVal = createIntCast(rewriter, resultVal,
mlir::cast<mlir::IntegerType>(resultTy));

if (info.getIsSigned()) {
assert(size <= storageSize);
unsigned highBits = storageSize - size;
Expand All @@ -3589,6 +3586,10 @@ mlir::LogicalResult CIRToLLVMSetBitfieldOpLowering::matchAndRewrite(
}
}

resultVal = createIntCast(rewriter, resultVal,
mlir::cast<mlir::IntegerType>(resultTy),
info.getIsSigned());

rewriter.replaceOp(op, resultVal);
return mlir::success();
}
Expand Down
12 changes: 12 additions & 0 deletions clang/test/CIR/CodeGen/bitfields.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s

struct __long {
struct __attribute__((__packed__)) {
Expand Down Expand Up @@ -129,3 +131,13 @@ void createU() {
void createD() {
D d = {1,2,3};
}

// check the -1 is stored to the ret value
// LLVM: define dso_local i32 {{@.*get_a.*}}
// LLVM: %[[V1:.*]] = alloca i32
// LLVM: store i32 -1, ptr %[[V1]], align 4
// LLVM: %[[V2:.*]] = load i32, ptr %[[V1]], align 4
// LLVM: ret i32 %[[V2:.*]]
int get_a(T *t) {
return (t->a = 7);
}
Loading