diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9798,7 +9798,10 @@ ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This, isa(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()) diff --git a/clang/test/CodeGenCXX/bitfield-layout.cpp b/clang/test/CodeGenCXX/bitfield-layout.cpp --- a/clang/test/CodeGenCXX/bitfield-layout.cpp +++ b/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 +}