diff options
author | Alex Richardson <alexrichardson@google.com> | 2022-11-18 12:14:00 +0000 |
---|---|---|
committer | Alex Richardson <alexrichardson@google.com> | 2022-11-30 20:24:01 +0000 |
commit | a602f76a2406cc3edd6b297ede3583b26513a34c (patch) | |
tree | ff026455684f7aeff22923436910e84965cbdbfe /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | 57b1c0250d5da6ac5342f10cd8f046412a46f153 (diff) | |
download | llvm-a602f76a2406cc3edd6b297ede3583b26513a34c.zip llvm-a602f76a2406cc3edd6b297ede3583b26513a34c.tar.gz llvm-a602f76a2406cc3edd6b297ede3583b26513a34c.tar.bz2 |
[clang][TargetInfo] Use LangAS for getPointer{Width,Align}()
Mixing LLVM and Clang address spaces can result in subtle bugs, and there
is no need for this hook to use the LLVM IR level address spaces.
Most of this change is just replacing zero with LangAS::Default,
but it also allows us to remove a few calls to getTargetAddressSpace().
This also removes a stale comment+workaround in
CGDebugInfo::CreatePointerLikeType(): ASTContext::getTypeSize() does
return the expected size for ReferenceType (and handles address spaces).
Differential Revision: https://reviews.llvm.org/D138295
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 4b56e15..efcd44e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1145,13 +1145,11 @@ llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag, QualType PointeeTy, llvm::DIFile *Unit) { // Bit size, align and offset of the type. - // Size is always the size of a pointer. We can't use getTypeSize here - // because that does not return the correct value for references. - unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(PointeeTy); - uint64_t Size = CGM.getTarget().getPointerWidth(AddressSpace); + // Size is always the size of a pointer. + uint64_t Size = CGM.getContext().getTypeSize(Ty); auto Align = getTypeAlignIfRequired(Ty, CGM.getContext()); - Optional<unsigned> DWARFAddressSpace = - CGM.getTarget().getDWARFAddressSpace(AddressSpace); + Optional<unsigned> DWARFAddressSpace = CGM.getTarget().getDWARFAddressSpace( + CGM.getContext().getTargetAddressSpace(PointeeTy)); SmallVector<llvm::Metadata *, 4> Annots; auto *BTFAttrTy = dyn_cast<BTFTagAttributedType>(PointeeTy); @@ -1703,11 +1701,10 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType( if (isa<ClassTemplateSpecializationDecl>(RD)) { // Create pointer type directly in this case. const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr); - QualType PointeeTy = ThisPtrTy->getPointeeType(); - unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy); - uint64_t Size = CGM.getTarget().getPointerWidth(AS); + uint64_t Size = CGM.getContext().getTypeSize(ThisPtrTy); auto Align = getTypeAlignIfRequired(ThisPtrTy, CGM.getContext()); - llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit); + llvm::DIType *PointeeType = + getOrCreateType(ThisPtrTy->getPointeeType(), Unit); llvm::DIType *ThisPtrType = DBuilder.createPointerType(PointeeType, Size, Align); TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType); @@ -4383,7 +4380,7 @@ CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, CharUnits Align = CGM.getContext().getDeclAlign(VD); if (Align > CGM.getContext().toCharUnitsFromBits( - CGM.getTarget().getPointerAlign(0))) { + CGM.getTarget().getPointerAlign(LangAS::Default))) { CharUnits FieldOffsetInBytes = CGM.getContext().toCharUnitsFromBits(FieldOffset); CharUnits AlignedOffsetInBytes = FieldOffsetInBytes.alignTo(Align); @@ -4483,7 +4480,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD, Expr.push_back(llvm::dwarf::DW_OP_plus_uconst); // offset of __forwarding field offset = CGM.getContext().toCharUnitsFromBits( - CGM.getTarget().getPointerWidth(0)); + CGM.getTarget().getPointerWidth(LangAS::Default)); Expr.push_back(offset.getQuantity()); Expr.push_back(llvm::dwarf::DW_OP_deref); Expr.push_back(llvm::dwarf::DW_OP_plus_uconst); |