[PATCH] D93101: [Clang][Codegen] Truncate initializers of union bitfield members
Tomas Matheson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 14 01:55:52 PST 2020
tmatheson updated this revision to Diff 311529.
tmatheson added a comment.
Rebased
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93101/new/
https://reviews.llvm.org/D93101
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGenCXX/bitfield-layout.cpp
Index: clang/test/CodeGenCXX/bitfield-layout.cpp
===================================================================
--- clang/test/CodeGenCXX/bitfield-layout.cpp
+++ clang/test/CodeGenCXX/bitfield-layout.cpp
@@ -84,3 +84,12 @@
// CHECK: ret i32 0
return 0;
}
+
+// CHECK: define i32 @_Z10test_truncv()
+int test_trunc() {
+ union {
+ int i : 4;
+ } U = {15};
+ return U.i;
+ // CHECK: ret i32 -1
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9798,7 +9798,10 @@
ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This,
isa<CXXDefaultInitExpr>(InitExpr));
- return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, InitExpr);
+ return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, InitExpr) ||
+ (Field->isBitField() &&
+ truncateBitfieldValue(Info, InitExpr, Result.getUnionValue(),
+ Field));
}
if (!Result.hasValue())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93101.311529.patch
Type: text/x-patch
Size: 1098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201214/6b43c72f/attachment.bin>
More information about the cfe-commits
mailing list