llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: puneeth_aditya_5656 (mugiwaraluffy56)
<details>
<summary>Changes</summary>
## Summary
- Use `CreateMemTemp` instead of `CreateIRTemp` for return value allocas
- Ensures proper memory type for _BitInt types that have different IR and
memory representations
- For _BitInt(121), the IR type is i121 but memory type is i128, fixing the
coercion to {i64, i64}
Fixes #<!-- -->179448
## Test plan
- Added test case for _BitInt(121) return value in ext-int.c
---
Full diff: https://github.com/llvm/llvm-project/pull/179456.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+3-1)
- (modified) clang/test/CodeGen/ext-int.c (+9)
``````````diff
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp
b/clang/lib/CodeGen/CodeGenFunction.cpp
index fbae2433ec278..8519ff1dd7efd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1248,7 +1248,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
QualType RetTy,
ReturnValue = Address(Addr, ConvertType(RetTy),
CGM.getNaturalTypeAlignment(RetTy), KnownNonNull);
} else {
- ReturnValue = CreateIRTemp(RetTy, "retval");
+ // Use CreateMemTemp to ensure proper memory representation for types
+ // like _BitInt that may have different IR and memory types.
+ ReturnValue = CreateMemTemp(RetTy, "retval");
// Tell the epilog emitter to autorelease the result. We do this
// now so that various specialized functions can suppress it
diff --git a/clang/test/CodeGen/ext-int.c b/clang/test/CodeGen/ext-int.c
index a12b11adbf00d..319bbe86558e8 100644
--- a/clang/test/CodeGen/ext-int.c
+++ b/clang/test/CodeGen/ext-int.c
@@ -252,4 +252,13 @@ void bitField() {
// LIN64: store i64 %bf.set4, ptr %s1, align 8
}
+// GH#179448: Ensure the return value alloca uses the memory type (i128)
+// instead of the IR type (i121) to avoid miscompilation when coercing
+// the return value to {i64, i64}.
+// LIN64: define {{.*}}{ i64, i64 } @returnBitInt121(i64 {{.*}}, i64 {{.*}})
+// LIN64: %retval = alloca i128, align 8
+_BitInt(121) returnBitInt121(_BitInt(121) a) {
+ return a;
+}
+
#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/179456
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits