@@ -4874,40 +4874,6 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
4874
4874
return D;
4875
4875
}
4876
4876
4877
- llvm::DIType *CGDebugInfo::CreateBindingDeclType (const BindingDecl *BD) {
4878
- llvm::DIFile *Unit = getOrCreateFile (BD->getLocation ());
4879
-
4880
- // If the declaration is bound to a bitfield struct field, its type may have a
4881
- // size that is different from its deduced declaration type's.
4882
- if (const MemberExpr *ME = dyn_cast<MemberExpr>(BD->getBinding ())) {
4883
- if (const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl ())) {
4884
- if (FD->isBitField ()) {
4885
- ASTContext &Context = CGM.getContext ();
4886
- const CGRecordLayout &RL =
4887
- CGM.getTypes ().getCGRecordLayout (FD->getParent ());
4888
- const CGBitFieldInfo &Info = RL.getBitFieldInfo (FD);
4889
-
4890
- // Find an integer type with the same bitwidth as the bitfield size. If
4891
- // no suitable type is present in the target, give up on producing debug
4892
- // information as it would be wrong. It is certainly possible to produce
4893
- // correct debug info, but the logic isn't currently implemented.
4894
- uint64_t BitfieldSizeInBits = Info.Size ;
4895
- QualType IntTy =
4896
- Context.getIntTypeForBitwidth (BitfieldSizeInBits, Info.IsSigned );
4897
- if (IntTy.isNull ())
4898
- return nullptr ;
4899
- Qualifiers Quals = BD->getType ().getQualifiers ();
4900
- QualType FinalTy = Context.getQualifiedType (IntTy, Quals);
4901
- llvm::DIType *Ty = getOrCreateType (FinalTy, Unit);
4902
- assert (Ty);
4903
- return Ty;
4904
- }
4905
- }
4906
- }
4907
-
4908
- return getOrCreateType (BD->getType (), Unit);
4909
- }
4910
-
4911
4877
llvm::DILocalVariable *CGDebugInfo::EmitDeclare (const BindingDecl *BD,
4912
4878
llvm::Value *Storage,
4913
4879
std::optional<unsigned > ArgNo,
@@ -4922,7 +4888,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
4922
4888
if (isa<DeclRefExpr>(BD->getBinding ()))
4923
4889
return nullptr ;
4924
4890
4925
- llvm::DIType *Ty = CreateBindingDeclType (BD);
4891
+ llvm::DIFile *Unit = getOrCreateFile (BD->getLocation ());
4892
+ llvm::DIType *Ty = getOrCreateType (BD->getType (), Unit);
4926
4893
4927
4894
// If there is no debug info for this type then do not emit debug info
4928
4895
// for this variable.
@@ -4948,7 +4915,6 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
4948
4915
unsigned Column = getColumnNumber (BD->getLocation ());
4949
4916
StringRef Name = BD->getName ();
4950
4917
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back ());
4951
- llvm::DIFile *Unit = getOrCreateFile (BD->getLocation ());
4952
4918
// Create the descriptor for the variable.
4953
4919
llvm::DILocalVariable *D = DBuilder.createAutoVariable (
4954
4920
Scope, Name, Unit, Line, Ty, CGM.getLangOpts ().Optimize ,
@@ -4962,13 +4928,29 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
4962
4928
const ASTRecordLayout &layout =
4963
4929
CGM.getContext ().getASTRecordLayout (parent);
4964
4930
const uint64_t fieldOffset = layout.getFieldOffset (fieldIndex);
4965
-
4966
- if (fieldOffset != 0 ) {
4967
- // Currently if the field offset is not a multiple of byte, the produced
4968
- // location would not be accurate. Therefore give up.
4969
- if (fieldOffset % CGM.getContext ().getCharWidth () != 0 )
4970
- return nullptr ;
4971
-
4931
+ if (FD->isBitField ()) {
4932
+ const CGRecordLayout &RL =
4933
+ CGM.getTypes ().getCGRecordLayout (FD->getParent ());
4934
+ const CGBitFieldInfo &Info = RL.getBitFieldInfo (FD);
4935
+ // Use DW_OP_plus_uconst to adjust to the start of the bitfield
4936
+ // storage.
4937
+ if (!Info.StorageOffset .isZero ()) {
4938
+ Expr.push_back (llvm::dwarf::DW_OP_plus_uconst);
4939
+ Expr.push_back (Info.StorageOffset .getQuantity ());
4940
+ }
4941
+ // Use LLVM_extract_bits to extract the appropriate bits from this
4942
+ // bitfield.
4943
+ Expr.push_back (Info.IsSigned
4944
+ ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
4945
+ : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
4946
+ Expr.push_back (Info.Offset );
4947
+ // If we have an oversized bitfield then the value won't be more than
4948
+ // the size of the type.
4949
+ const uint64_t TypeSize = CGM.getContext ().getTypeSize (BD->getType ());
4950
+ Expr.push_back (std::min ((uint64_t )Info.Size , TypeSize));
4951
+ } else if (fieldOffset != 0 ) {
4952
+ assert (fieldOffset % CGM.getContext ().getCharWidth () == 0 &&
4953
+ " Unexpected non-bitfield with non-byte-aligned offset" );
4972
4954
Expr.push_back (llvm::dwarf::DW_OP_plus_uconst);
4973
4955
Expr.push_back (
4974
4956
CGM.getContext ().toCharUnitsFromBits (fieldOffset).getQuantity ());
0 commit comments