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