arichardson created this revision. arichardson added a reviewer: clang. Herald added subscribers: steakhal, kosarev, mattd, gchakrabarti, asavonic, martong, kerbowa, atanasyan, jrtc27, jvesely, sdardis. Herald added a reviewer: aaron.ballman. Herald added a reviewer: NoQ. Herald added a project: All. arichardson requested review of this revision. Herald added subscribers: cfe-commits, jholewinski. Herald added a project: clang.
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). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138295 Files: clang/include/clang/Basic/TargetInfo.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ItaniumCXXABI.cpp clang/lib/AST/Mangle.cpp clang/lib/AST/MicrosoftCXXABI.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/RecordLayoutBuilder.cpp clang/lib/AST/VTableBuilder.cpp clang/lib/Basic/Targets/AMDGPU.cpp clang/lib/Basic/Targets/AMDGPU.h clang/lib/Basic/Targets/Mips.cpp clang/lib/Basic/Targets/NVPTX.cpp clang/lib/Basic/Targets/X86.h clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CGObjCGNU.cpp clang/lib/CodeGen/CGObjCMac.cpp clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/CodeGen/PatternInit.cpp clang/lib/CodeGen/SwiftCallingConv.cpp clang/lib/CodeGen/TargetInfo.cpp clang/lib/Frontend/InitPreprocessor.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaType.cpp clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp clang/unittests/CodeGen/TestCompiler.h
Index: clang/unittests/CodeGen/TestCompiler.h =================================================================== --- clang/unittests/CodeGen/TestCompiler.h +++ clang/unittests/CodeGen/TestCompiler.h @@ -48,7 +48,7 @@ std::make_shared<clang::TargetOptions>(compiler.getTargetOpts()))); const clang::TargetInfo &TInfo = compiler.getTarget(); - PtrSize = TInfo.getPointerWidth(0) / 8; + PtrSize = TInfo.getPointerWidth(clang::LangAS::Default) / 8; compiler.createFileManager(); compiler.createSourceManager(compiler.getFileManager()); Index: clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp @@ -72,7 +72,7 @@ public: WalkAST(BugReporter &br, const CheckerBase *checker, AnalysisDeclContext *ac) : BR(br), Checker(checker), AC(ac), ASTC(AC->getASTContext()), - PtrWidth(ASTC.getTargetInfo().getPointerWidth(0)) {} + PtrWidth(ASTC.getTargetInfo().getPointerWidth(LangAS::Default)) {} // Statement visitor methods. void VisitChildren(Stmt *S); Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -7288,7 +7288,8 @@ // Add address space to type based on its attributes. LangAS ASIdx = LangAS::Default; - uint64_t PtrWidth = S.Context.getTargetInfo().getPointerWidth(0); + uint64_t PtrWidth = + S.Context.getTargetInfo().getPointerWidth(LangAS::Default); if (PtrWidth == 32) { if (Attrs[attr::Ptr64]) ASIdx = LangAS::ptr64; Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -2661,7 +2661,7 @@ // tree? Or should the consumer just recalculate the value? // FIXME: Using a dummy value will interact poorly with attribute enable_if. IntegerLiteral Size( - Context, llvm::APInt::getZero(Context.getTargetInfo().getPointerWidth(0)), + Context, llvm::APInt::getZero(Context.getTargetInfo().getPointerWidth(LangAS::Default)), Context.getSizeType(), SourceLocation()); AllocArgs.push_back(&Size); Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -16720,7 +16720,7 @@ // The type of __null will be int or long, depending on the size of // pointers on the target. QualType Ty; - unsigned pw = Context.getTargetInfo().getPointerWidth(0); + unsigned pw = Context.getTargetInfo().getPointerWidth(LangAS::Default); if (pw == Context.getTargetInfo().getIntWidth()) Ty = Context.IntTy; else if (pw == Context.getTargetInfo().getLongWidth()) Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -4506,7 +4506,7 @@ break; case 7: if (Str == "pointer") - DestWidth = S.Context.getTargetInfo().getPointerWidth(0); + DestWidth = S.Context.getTargetInfo().getPointerWidth(LangAS::Default); break; case 11: if (Str == "unwind_word") Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -15984,9 +15984,8 @@ return; if (index.isUnsigned() || !index.isNegative()) { const auto &ASTC = getASTContext(); - unsigned AddrBits = - ASTC.getTargetInfo().getPointerWidth(ASTC.getTargetAddressSpace( - EffectiveType->getCanonicalTypeInternal())); + unsigned AddrBits = ASTC.getTargetInfo().getPointerWidth( + EffectiveType->getCanonicalTypeInternal().getAddressSpace()); if (index.getBitWidth() < AddrBits) index = index.zext(AddrBits); Optional<CharUnits> ElemCharUnits = Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ clang/lib/Frontend/InitPreprocessor.cpp @@ -948,14 +948,14 @@ Builder.defineMacro("__LITTLE_ENDIAN__"); } - if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64 - && TI.getIntWidth() == 32) { + if (TI.getPointerWidth(LangAS::Default) == 64 && TI.getLongWidth() == 64 && + TI.getIntWidth() == 32) { Builder.defineMacro("_LP64"); Builder.defineMacro("__LP64__"); } - if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32 - && TI.getIntWidth() == 32) { + if (TI.getPointerWidth(LangAS::Default) == 32 && TI.getLongWidth() == 32 && + TI.getIntWidth() == 32) { Builder.defineMacro("_ILP32"); Builder.defineMacro("__ILP32__"); } @@ -988,7 +988,8 @@ DefineTypeSizeAndWidth("__SIZE", TI.getSizeType(), TI, Builder); DefineTypeSizeAndWidth("__UINTMAX", TI.getUIntMaxType(), TI, Builder); - DefineTypeSizeAndWidth("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder); + DefineTypeSizeAndWidth("__PTRDIFF", TI.getPtrDiffType(LangAS::Default), TI, + Builder); DefineTypeSizeAndWidth("__INTPTR", TI.getIntPtrType(), TI, Builder); DefineTypeSizeAndWidth("__UINTPTR", TI.getUIntPtrType(), TI, Builder); @@ -998,10 +999,12 @@ DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder); DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder); DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder); - DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder); + DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(LangAS::Default), + TI, Builder); DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder); DefineTypeSizeof("__SIZEOF_PTRDIFF_T__", - TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder); + TI.getTypeWidth(TI.getPtrDiffType(LangAS::Default)), TI, + Builder); DefineTypeSizeof("__SIZEOF_SIZE_T__", TI.getTypeWidth(TI.getSizeType()), TI, Builder); DefineTypeSizeof("__SIZEOF_WCHAR_T__", @@ -1019,8 +1022,8 @@ DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder); Builder.defineMacro("__UINTMAX_C_SUFFIX__", TI.getTypeConstantSuffix(TI.getUIntMaxType())); - DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder); - DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder); + DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(LangAS::Default), Builder); + DefineFmt("__PTRDIFF", TI.getPtrDiffType(LangAS::Default), TI, Builder); DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder); DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder); DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder); @@ -1051,7 +1054,7 @@ // Define a __POINTER_WIDTH__ macro for stdint.h. Builder.defineMacro("__POINTER_WIDTH__", - Twine((int)TI.getPointerWidth(0))); + Twine((int)TI.getPointerWidth(LangAS::Default))); // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc. Builder.defineMacro("__BIGGEST_ALIGNMENT__", @@ -1164,8 +1167,9 @@ DEFINE_LOCK_FREE_MACRO(INT, Int); DEFINE_LOCK_FREE_MACRO(LONG, Long); DEFINE_LOCK_FREE_MACRO(LLONG, LongLong); - Builder.defineMacro(Prefix + "POINTER_LOCK_FREE", - getLockFreeValue(TI.getPointerWidth(0), TI)); + Builder.defineMacro( + Prefix + "POINTER_LOCK_FREE", + getLockFreeValue(TI.getPointerWidth(LangAS::Default), TI)); #undef DEFINE_LOCK_FREE_MACRO }; addLockFreeMacros("__CLANG_ATOMIC_"); Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -141,7 +141,7 @@ if (type->isPointerTy()) { intCount++; } else if (auto intTy = dyn_cast<llvm::IntegerType>(type)) { - auto ptrWidth = cgt.getTarget().getPointerWidth(0); + auto ptrWidth = cgt.getTarget().getPointerWidth(LangAS::Default); intCount += (intTy->getBitWidth() + ptrWidth - 1) / ptrWidth; } else { assert(type->isVectorTy() || type->isFloatingPointTy()); @@ -5832,7 +5832,7 @@ Alignment = Alignment < 128 ? 64 : 128; } else { Alignment = std::max(getContext().getTypeAlign(Ty), - (unsigned)getTarget().getPointerWidth(0)); + (unsigned)getTarget().getPointerWidth(LangAS::Default)); } Size = llvm::alignTo(Size, Alignment); @@ -6247,7 +6247,7 @@ if (!isAggregateTypeForABI(Ty) && !isIllegalVectorType(Ty)) return EmitVAArgInstr(CGF, VAListAddr, Ty, ABIArgInfo::getDirect()); - uint64_t PointerSize = getTarget().getPointerWidth(0) / 8; + uint64_t PointerSize = getTarget().getPointerWidth(LangAS::Default) / 8; CharUnits SlotSize = CharUnits::fromQuantity(PointerSize); // Empty records are ignored for parameter passing purposes. @@ -8199,7 +8199,7 @@ // Integer arguments are promoted to 32-bit on O32 and 64-bit on N32/N64. // Pointers are also promoted in the same way but this only matters for N32. unsigned SlotSizeInBits = IsO32 ? 32 : 64; - unsigned PtrWidth = getTarget().getPointerWidth(0); + unsigned PtrWidth = getTarget().getPointerWidth(LangAS::Default); bool DidPromote = false; if ((Ty->isIntegerType() && getContext().getIntWidth(Ty) < SlotSizeInBits) || @@ -12201,7 +12201,7 @@ case llvm::Triple::riscv32: case llvm::Triple::riscv64: { StringRef ABIStr = getTarget().getABI(); - unsigned XLen = getTarget().getPointerWidth(0); + unsigned XLen = getTarget().getPointerWidth(LangAS::Default); unsigned ABIFLen = 0; if (ABIStr.endswith("f")) ABIFLen = 32; @@ -12296,7 +12296,7 @@ else if (ABIStr.endswith("d")) ABIFRLen = 64; return SetCGInfo(new LoongArchTargetCodeGenInfo( - Types, getTarget().getPointerWidth(0), ABIFRLen)); + Types, getTarget().getPointerWidth(LangAS::Default), ABIFRLen)); } } } Index: clang/lib/CodeGen/SwiftCallingConv.cpp =================================================================== --- clang/lib/CodeGen/SwiftCallingConv.cpp +++ clang/lib/CodeGen/SwiftCallingConv.cpp @@ -652,7 +652,7 @@ CharUnits swiftcall::getMaximumVoluntaryIntegerSize(CodeGenModule &CGM) { // Currently always the size of an ordinary pointer. return CGM.getContext().toCharUnitsFromBits( - CGM.getContext().getTargetInfo().getPointerWidth(0)); + CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default)); } CharUnits swiftcall::getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type) { Index: clang/lib/CodeGen/PatternInit.cpp =================================================================== --- clang/lib/CodeGen/PatternInit.cpp +++ clang/lib/CodeGen/PatternInit.cpp @@ -43,8 +43,8 @@ } if (Ty->isPtrOrPtrVectorTy()) { auto *PtrTy = cast<llvm::PointerType>(Ty->getScalarType()); - unsigned PtrWidth = CGM.getContext().getTargetInfo().getPointerWidth( - PtrTy->getAddressSpace()); + unsigned PtrWidth = + CGM.getDataLayout().getPointerSizeInBits(PtrTy->getAddressSpace()); if (PtrWidth > 64) llvm_unreachable("pattern initialization of unsupported pointer width"); llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth); Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -458,7 +458,7 @@ friend struct MSRTTIBuilder; bool isImageRelative() const { - return CGM.getTarget().getPointerWidth(/*AddrSpace=*/0) == 64; + return CGM.getTarget().getPointerWidth(LangAS::Default) == 64; } // 5 routines for constructing the llvm types for MS RTTI structs. @@ -1671,7 +1671,7 @@ CharUnits AddressPoint = getContext().getLangOpts().RTTIData ? getContext().toCharUnitsFromBits( - getContext().getTargetInfo().getPointerWidth(0)) + getContext().getTargetInfo().getPointerWidth(LangAS::Default)) : CharUnits::Zero(); if (Info.PathToIntroducingObject.empty()) { @@ -1944,7 +1944,9 @@ if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) { VFunc = CGF.EmitVTableTypeCheckedLoad( getObjectWithVPtr(), VTable, Ty, - ML.Index * CGM.getContext().getTargetInfo().getPointerWidth(0) / 8); + ML.Index * + CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default) / + 8); } else { if (CGM.getCodeGenOpts().PrepareForLTO) CGF.EmitTypeMetadataCodeForVCall(getObjectWithVPtr(), VTable, Loc); Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1002,7 +1002,7 @@ } else { const ASTContext &Context = getContext(); CharUnits PointerWidth = Context.toCharUnitsFromBits( - Context.getTargetInfo().getPointerWidth(0)); + Context.getTargetInfo().getPointerWidth(LangAS::Default)); VTableOffset = Index * PointerWidth.getQuantity(); } @@ -1879,7 +1879,7 @@ // values are read. unsigned PAlign = CGM.getItaniumVTableContext().isRelativeLayout() ? 32 - : CGM.getTarget().getPointerAlign(0); + : CGM.getTarget().getPointerAlign(LangAS::Default); VTable = CGM.CreateOrReplaceCXXRuntimeVariable( Name, VTableType, llvm::GlobalValue::ExternalLinkage, @@ -1924,7 +1924,9 @@ if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) { VFunc = CGF.EmitVTableTypeCheckedLoad( MethodDecl->getParent(), VTable, TyPtr, - VTableIndex * CGM.getContext().getTargetInfo().getPointerWidth(0) / 8); + VTableIndex * + CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default) / + 8); } else { CGF.EmitTypeMetadataCodeForVCall(MethodDecl->getParent(), VTable, Loc); @@ -3875,8 +3877,8 @@ if (CGM.supportsCOMDAT() && GV->isWeakForLinker()) GV->setComdat(M.getOrInsertComdat(GV->getName())); - CharUnits Align = - CGM.getContext().toCharUnitsFromBits(CGM.getTarget().getPointerAlign(0)); + CharUnits Align = CGM.getContext().toCharUnitsFromBits( + CGM.getTarget().getPointerAlign(LangAS::Default)); GV->setAlignment(Align.getAsAlign()); // The Itanium ABI specifies that type_info objects must be globally @@ -4054,7 +4056,8 @@ // LLP64 platforms. QualType OffsetFlagsTy = CGM.getContext().LongTy; const TargetInfo &TI = CGM.getContext().getTargetInfo(); - if (TI.getTriple().isOSCygMing() && TI.getPointerWidth(0) > TI.getLongWidth()) + if (TI.getTriple().isOSCygMing() && + TI.getPointerWidth(LangAS::Default) > TI.getLongWidth()) OffsetFlagsTy = CGM.getContext().LongLongTy; llvm::Type *OffsetFlagsLTy = CGM.getTypes().ConvertType(OffsetFlagsTy); Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -123,9 +123,9 @@ BFloatTy = llvm::Type::getBFloatTy(LLVMContext); FloatTy = llvm::Type::getFloatTy(LLVMContext); DoubleTy = llvm::Type::getDoubleTy(LLVMContext); - PointerWidthInBits = C.getTargetInfo().getPointerWidth(0); + PointerWidthInBits = C.getTargetInfo().getPointerWidth(LangAS::Default); PointerAlignInBytes = - C.toCharUnitsFromBits(C.getTargetInfo().getPointerAlign(0)).getQuantity(); + C.toCharUnitsFromBits(C.getTargetInfo().getPointerAlign(LangAS::Default)).getQuantity(); SizeSizeInBytes = C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity(); IntAlignInBytes = Index: clang/lib/CodeGen/CGVTables.cpp =================================================================== --- clang/lib/CodeGen/CGVTables.cpp +++ clang/lib/CodeGen/CGVTables.cpp @@ -1281,8 +1281,8 @@ if (!getCodeGenOpts().LTOUnit) return; - CharUnits PointerWidth = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); + CharUnits PointerWidth = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerWidth(LangAS::Default)); typedef std::pair<const CXXRecordDecl *, unsigned> AddressPoint; std::vector<AddressPoint> AddressPoints; Index: clang/lib/CodeGen/CGObjCMac.cpp =================================================================== --- clang/lib/CodeGen/CGObjCMac.cpp +++ clang/lib/CodeGen/CGObjCMac.cpp @@ -2408,7 +2408,7 @@ if (GCAttr == Qualifiers::Strong) { assert(CGM.getContext().getTypeSize(type) - == CGM.getTarget().getPointerWidth(0)); + == CGM.getTarget().getPointerWidth(LangAS::Default)); IvarsInfo.push_back(IvarInfo(fieldOffset, /*size in words*/ 1)); } } @@ -2701,7 +2701,7 @@ llvm::Constant *nullPtr = llvm::Constant::getNullValue(CGM.Int8PtrTy); if (RunSkipBlockVars.empty()) return nullPtr; - unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(0); + unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(LangAS::Default); unsigned ByteSizeInBits = CGM.getTarget().getCharWidth(); unsigned WordSizeInBytes = WordSizeInBits/ByteSizeInBits; @@ -2887,7 +2887,7 @@ RunSkipBlockVars.clear(); bool hasUnion = false; - unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(0); + unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(LangAS::Default); unsigned ByteSizeInBits = CGM.getTarget().getCharWidth(); unsigned WordSizeInBytes = WordSizeInBits/ByteSizeInBits; Index: clang/lib/CodeGen/CGObjCGNU.cpp =================================================================== --- clang/lib/CodeGen/CGObjCGNU.cpp +++ clang/lib/CodeGen/CGObjCGNU.cpp @@ -985,7 +985,7 @@ auto LiteralLength = SL->getLength(); - if ((CGM.getTarget().getPointerWidth(0) == 64) && + if ((CGM.getTarget().getPointerWidth(LangAS::Default) == 64) && (LiteralLength < 9) && !isNonASCII) { // Tiny strings are only used on 64-bit platforms. They store 8 7-bit // ASCII characters in the high 56 bits, followed by a 4-bit length and a Index: clang/lib/CodeGen/CGExprAgg.cpp =================================================================== --- clang/lib/CodeGen/CGExprAgg.cpp +++ clang/lib/CodeGen/CGExprAgg.cpp @@ -1926,7 +1926,7 @@ // Reference values are always non-null and have the width of a pointer. if (Field->getType()->isReferenceType()) NumNonZeroBytes += CGF.getContext().toCharUnitsFromBits( - CGF.getTarget().getPointerWidth(0)); + CGF.getTarget().getPointerWidth(LangAS::Default)); else NumNonZeroBytes += GetNumNonZeroBytesInInit(E, CGF); } Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -1145,13 +1145,11 @@ 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,12 @@ 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); + assert(ThisPtrTy->getPointeeType().getAddressSpace() == LangAS::Default && + "this pointer not in default address space?"); 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 +4382,7 @@ 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 +4482,7 @@ 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); Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -4458,7 +4458,7 @@ if (Arg->getType()->isIntegerType() && getContext().getTypeSize(Arg->getType()) < - getContext().getTargetInfo().getPointerWidth(0) && + getContext().getTargetInfo().getPointerWidth(LangAS::Default) && Arg->isNullPointerConstant(getContext(), Expr::NPC_ValueDependentIsNotNull)) { return getContext().getIntPtrType(); Index: clang/lib/CodeGen/CGBlocks.cpp =================================================================== --- clang/lib/CodeGen/CGBlocks.cpp +++ clang/lib/CodeGen/CGBlocks.cpp @@ -502,12 +502,10 @@ if (CGM.getLangOpts().OpenCL) { // The header is basically 'struct { int; int; generic void *; // custom_fields; }'. Assert that struct is packed. - auto GenericAS = - CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic); - auto GenPtrAlign = - CharUnits::fromQuantity(CGM.getTarget().getPointerAlign(GenericAS) / 8); - auto GenPtrSize = - CharUnits::fromQuantity(CGM.getTarget().getPointerWidth(GenericAS) / 8); + auto GenPtrAlign = CharUnits::fromQuantity( + CGM.getTarget().getPointerAlign(LangAS::opencl_generic) / 8); + auto GenPtrSize = CharUnits::fromQuantity( + CGM.getTarget().getPointerWidth(LangAS::opencl_generic) / 8); assert(CGM.getIntSize() <= GenPtrSize); assert(CGM.getIntAlign() <= GenPtrAlign); assert((2 * CGM.getIntSize()).isMultipleOf(GenPtrAlign)); @@ -806,9 +804,7 @@ IsOpenCL ? CGM.getOpenCLRuntime().getGenericVoidPointerType() : VoidPtrTy; LangAS GenVoidPtrAddr = IsOpenCL ? LangAS::opencl_generic : LangAS::Default; auto GenVoidPtrSize = CharUnits::fromQuantity( - CGM.getTarget().getPointerWidth( - CGM.getContext().getTargetAddressSpace(GenVoidPtrAddr)) / - 8); + CGM.getTarget().getPointerWidth(GenVoidPtrAddr) / 8); // Using the computed layout, generate the actual block function. bool isLambdaConv = blockInfo.getBlockDecl()->isConversionFromLambda(); CodeGenFunction BlockCGF{CGM, true}; Index: clang/lib/Basic/Targets/X86.h =================================================================== --- clang/lib/Basic/Targets/X86.h +++ clang/lib/Basic/Targets/X86.h @@ -403,15 +403,16 @@ void setSupportedOpenCLOpts() override { supportAllOpenCLOpts(); } - uint64_t getPointerWidthV(unsigned AddrSpace) const override { - if (AddrSpace == ptr32_sptr || AddrSpace == ptr32_uptr) + uint64_t getPointerWidthV(LangAS AS) const override { + unsigned TargetAddrSpace = getTargetAddressSpace(AS); + if (TargetAddrSpace == ptr32_sptr || TargetAddrSpace == ptr32_uptr) return 32; - if (AddrSpace == ptr64) + if (TargetAddrSpace == ptr64) return 64; return PointerWidth; } - uint64_t getPointerAlignV(unsigned AddrSpace) const override { + uint64_t getPointerAlignV(LangAS AddrSpace) const override { return getPointerWidthV(AddrSpace); } Index: clang/lib/Basic/Targets/NVPTX.cpp =================================================================== --- clang/lib/Basic/Targets/NVPTX.cpp +++ clang/lib/Basic/Targets/NVPTX.cpp @@ -97,8 +97,8 @@ } // Copy properties from host target. - PointerWidth = HostTarget->getPointerWidth(/* AddrSpace = */ 0); - PointerAlign = HostTarget->getPointerAlign(/* AddrSpace = */ 0); + PointerWidth = HostTarget->getPointerWidth(LangAS::Default); + PointerAlign = HostTarget->getPointerAlign(LangAS::Default); BoolWidth = HostTarget->getBoolWidth(); BoolAlign = HostTarget->getBoolAlign(); IntWidth = HostTarget->getIntWidth(); @@ -119,7 +119,7 @@ HostTarget->getDefaultAlignForAttributeAligned(); SizeType = HostTarget->getSizeType(); IntMaxType = HostTarget->getIntMaxType(); - PtrDiffType = HostTarget->getPtrDiffType(/* AddrSpace = */ 0); + PtrDiffType = HostTarget->getPtrDiffType(LangAS::Default); IntPtrType = HostTarget->getIntPtrType(); WCharType = HostTarget->getWCharType(); WIntType = HostTarget->getWIntType(); Index: clang/lib/Basic/Targets/Mips.cpp =================================================================== --- clang/lib/Basic/Targets/Mips.cpp +++ clang/lib/Basic/Targets/Mips.cpp @@ -182,7 +182,7 @@ if (DisableMadd4) Builder.defineMacro("__mips_no_madd4", Twine(1)); - Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0))); + Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(LangAS::Default))); Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth())); Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth())); @@ -229,7 +229,7 @@ .Case("o32", 32) .Case("n32", 64) .Case("n64", 64) - .Default(getPointerWidth(0)); + .Default(getPointerWidth(LangAS::Default)); } bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const { Index: clang/lib/Basic/Targets/AMDGPU.h =================================================================== --- clang/lib/Basic/Targets/AMDGPU.h +++ clang/lib/Basic/Targets/AMDGPU.h @@ -95,17 +95,18 @@ void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override; - uint64_t getPointerWidthV(unsigned AddrSpace) const override { + uint64_t getPointerWidthV(LangAS AS) const override { if (isR600(getTriple())) return 32; + unsigned TargetAS = getTargetAddressSpace(AS); - if (AddrSpace == Private || AddrSpace == Local) + if (TargetAS == Private || TargetAS == Local) return 32; return 64; } - uint64_t getPointerAlignV(unsigned AddrSpace) const override { + uint64_t getPointerAlignV(LangAS AddrSpace) const override { return getPointerWidthV(AddrSpace); } Index: clang/lib/Basic/Targets/AMDGPU.cpp =================================================================== --- clang/lib/Basic/Targets/AMDGPU.cpp +++ clang/lib/Basic/Targets/AMDGPU.cpp @@ -370,8 +370,8 @@ WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64; AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics; - // Set pointer width and alignment for target address space 0. - PointerWidth = PointerAlign = getPointerWidthV(Generic); + // Set pointer width and alignment for the generic address space. + PointerWidth = PointerAlign = getPointerWidthV(LangAS::Default); if (getMaxPointerWidth() == 64) { LongWidth = LongAlign = 64; SizeType = UnsignedLong; Index: clang/lib/AST/VTableBuilder.cpp =================================================================== --- clang/lib/AST/VTableBuilder.cpp +++ clang/lib/AST/VTableBuilder.cpp @@ -670,8 +670,9 @@ // Under the relative ABI, the offset widths are 32-bit ints instead of // pointer widths. CharUnits OffsetWidth = Context.toCharUnitsFromBits( - VTables.isRelativeLayout() ? 32 - : Context.getTargetInfo().getPointerWidth(0)); + VTables.isRelativeLayout() + ? 32 + : Context.getTargetInfo().getPointerWidth(LangAS::Default)); CharUnits OffsetOffset = OffsetWidth * OffsetIndex; return OffsetOffset; Index: clang/lib/AST/RecordLayoutBuilder.cpp =================================================================== --- clang/lib/AST/RecordLayoutBuilder.cpp +++ clang/lib/AST/RecordLayoutBuilder.cpp @@ -1059,10 +1059,10 @@ // primary base, add it in now. } else if (RD->isDynamicClass()) { assert(DataSize == 0 && "Vtable pointer must be at offset zero!"); - CharUnits PtrWidth = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); - CharUnits PtrAlign = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerAlign(0)); + CharUnits PtrWidth = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerWidth(LangAS::Default)); + CharUnits PtrAlign = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerAlign(LangAS::Default)); EnsureVTablePointerAlignment(PtrAlign); HasOwnVFPtr = true; @@ -1912,11 +1912,9 @@ if (D->getType()->isIncompleteArrayType()) { setDeclInfo(true /* IsIncompleteArrayType */); } else if (const ReferenceType *RT = D->getType()->getAs<ReferenceType>()) { - unsigned AS = Context.getTargetAddressSpace(RT->getPointeeType()); - EffectiveFieldSize = FieldSize = Context.toCharUnitsFromBits( - Context.getTargetInfo().getPointerWidth(AS)); - FieldAlign = Context.toCharUnitsFromBits( - Context.getTargetInfo().getPointerAlign(AS)); + TypeInfoChars TI = Context.getTypeInfoInChars(RT); + EffectiveFieldSize = FieldSize = TI.Width; + FieldAlign = TI.Align; } else { setDeclInfo(false /* IsIncompleteArrayType */); @@ -2768,7 +2766,8 @@ // than the pointer size. if (const MaxFieldAlignmentAttr *MFAA = RD->getAttr<MaxFieldAlignmentAttr>()){ unsigned PackedAlignment = MFAA->getAlignment(); - if (PackedAlignment <= Context.getTargetInfo().getPointerWidth(0)) + if (PackedAlignment <= + Context.getTargetInfo().getPointerWidth(LangAS::Default)) MaxFieldAlignment = Context.toCharUnitsFromBits(PackedAlignment); } // Packed attribute forces max field alignment to be 1. @@ -2793,10 +2792,10 @@ SharedVBPtrBase = nullptr; // Calculate pointer size and alignment. These are used for vfptr and vbprt // injection. - PointerInfo.Size = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); - PointerInfo.Alignment = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerAlign(0)); + PointerInfo.Size = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerWidth(LangAS::Default)); + PointerInfo.Alignment = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerAlign(LangAS::Default)); // Respect pragma pack. if (!MaxFieldAlignment.isZero()) PointerInfo.Alignment = std::min(PointerInfo.Alignment, MaxFieldAlignment); Index: clang/lib/AST/MicrosoftMangle.cpp =================================================================== --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -340,22 +340,22 @@ MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_) : Context(C), Out(Out_), Structor(nullptr), StructorType(-1), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, const CXXConstructorDecl *D, CXXCtorType Type) : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, const CXXDestructorDecl *D, CXXDtorType Type) : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} raw_ostream &getStream() const { return Out; } @@ -776,7 +776,7 @@ const CXXMethodDecl *MD, const MethodVFTableLocation &ML) { // Get the vftable offset. CharUnits PointerWidth = getASTContext().toCharUnitsFromBits( - getASTContext().getTargetInfo().getPointerWidth(0)); + getASTContext().getTargetInfo().getPointerWidth(LangAS::Default)); uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity(); Out << "?_9"; Index: clang/lib/AST/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/AST/MicrosoftCXXABI.cpp +++ clang/lib/AST/MicrosoftCXXABI.cpp @@ -303,7 +303,7 @@ // The nominal struct is laid out with pointers followed by ints and aligned // to a pointer width if any are present and an int width otherwise. const TargetInfo &Target = Context.getTargetInfo(); - unsigned PtrSize = Target.getPointerWidth(0); + unsigned PtrSize = Target.getPointerWidth(LangAS::Default); unsigned IntSize = Target.getIntWidth(); unsigned Ptrs, Ints; @@ -318,7 +318,7 @@ if (Ptrs + Ints > 1 && Target.getTriple().isArch32Bit()) MPI.Align = 64; else if (Ptrs) - MPI.Align = Target.getPointerAlign(0); + MPI.Align = Target.getPointerAlign(LangAS::Default); else MPI.Align = Target.getIntAlign(); Index: clang/lib/AST/Mangle.cpp =================================================================== --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -230,11 +230,11 @@ if (AT->isIncompleteType()) break; // Size should be aligned to pointer size. - ArgWords += - llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) / - TI.getPointerWidth(0); + ArgWords += llvm::alignTo(ASTContext.getTypeSize(AT), + TI.getPointerWidth(LangAS::Default)) / + TI.getPointerWidth(LangAS::Default); } - Out << ((TI.getPointerWidth(0) / 8) * ArgWords); + Out << ((TI.getPointerWidth(LangAS::Default) / 8) * ArgWords); } void MangleContext::mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream &Out) { Index: clang/lib/AST/ItaniumCXXABI.cpp =================================================================== --- clang/lib/AST/ItaniumCXXABI.cpp +++ clang/lib/AST/ItaniumCXXABI.cpp @@ -224,7 +224,7 @@ MemberPointerInfo getMemberPointerInfo(const MemberPointerType *MPT) const override { const TargetInfo &Target = Context.getTargetInfo(); - TargetInfo::IntType PtrDiff = Target.getPtrDiffType(0); + TargetInfo::IntType PtrDiff = Target.getPtrDiffType(LangAS::Default); MemberPointerInfo MPI; MPI.Width = Target.getTypeWidth(PtrDiff); MPI.Align = Target.getTypeAlign(PtrDiff); @@ -251,8 +251,8 @@ return false; const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); - CharUnits PointerSize = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); + CharUnits PointerSize = Context.toCharUnitsFromBits( + Context.getTargetInfo().getPointerWidth(LangAS::Default)); return Layout.getNonVirtualSize() == PointerSize; } Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -1879,7 +1879,7 @@ uint64_t Width = EltInfo.Width.getQuantity() * Size; unsigned Align = EltInfo.Align.getQuantity(); if (!Context.getTargetInfo().getCXXABI().isMicrosoft() || - Context.getTargetInfo().getPointerWidth(0) == 64) + Context.getTargetInfo().getPointerWidth(LangAS::Default) == 64) Width = llvm::alignTo(Width, Align); return TypeInfoChars(CharUnits::fromQuantity(Width), CharUnits::fromQuantity(Align), @@ -1990,7 +1990,7 @@ uint64_t Width = 0; unsigned Align = 8; AlignRequirementKind AlignRequirement = AlignRequirementKind::None; - unsigned AS = 0; + LangAS AS = LangAS::Default; switch (T->getTypeClass()) { #define TYPE(Class, Base) #define ABSTRACT_TYPE(Class, Base) @@ -2025,7 +2025,7 @@ Align = EltInfo.Align; AlignRequirement = EltInfo.AlignRequirement; if (!getTargetInfo().getCXXABI().isMicrosoft() || - getTargetInfo().getPointerWidth(0) == 64) + getTargetInfo().getPointerWidth(LangAS::Default) == 64) Width = llvm::alignTo(Width, Align); break; } @@ -2225,14 +2225,15 @@ } break; case BuiltinType::NullPtr: - Width = Target->getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) - Align = Target->getPointerAlign(0); // == sizeof(void*) + Width = Target->getPointerWidth( + LangAS::Default); // C++ 3.9.1p11: sizeof(nullptr_t) + Align = Target->getPointerAlign(LangAS::Default); // == sizeof(void*) break; case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: - Width = Target->getPointerWidth(0); - Align = Target->getPointerAlign(0); + Width = Target->getPointerWidth(LangAS::Default); + Align = Target->getPointerAlign(LangAS::Default); break; case BuiltinType::OCLSampler: case BuiltinType::OCLEvent: @@ -2245,8 +2246,7 @@ #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ case BuiltinType::Id: #include "clang/Basic/OpenCLExtensionTypes.def" - AS = getTargetAddressSpace( - Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T))); + AS = Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; @@ -2291,11 +2291,11 @@ } break; case Type::ObjCObjectPointer: - Width = Target->getPointerWidth(0); - Align = Target->getPointerAlign(0); + Width = Target->getPointerWidth(LangAS::Default); + Align = Target->getPointerAlign(LangAS::Default); break; case Type::BlockPointer: - AS = getTargetAddressSpace(cast<BlockPointerType>(T)->getPointeeType()); + AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace(); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; @@ -2303,12 +2303,12 @@ case Type::RValueReference: // alignof and sizeof should never enter this code path here, so we go // the pointer route. - AS = getTargetAddressSpace(cast<ReferenceType>(T)->getPointeeType()); + AS = cast<ReferenceType>(T)->getPointeeType().getAddressSpace(); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; case Type::Pointer: - AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); + AS = cast<PointerType>(T)->getPointeeType().getAddressSpace(); Width = Target->getPointerWidth(AS); Align = Target->getPointerAlign(AS); break; @@ -2465,8 +2465,8 @@ break; case Type::Pipe: - Width = Target->getPointerWidth(getTargetAddressSpace(LangAS::opencl_global)); - Align = Target->getPointerAlign(getTargetAddressSpace(LangAS::opencl_global)); + Width = Target->getPointerWidth(LangAS::opencl_global); + Align = Target->getPointerAlign(LangAS::opencl_global); break; } @@ -5975,14 +5975,14 @@ /// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). QualType ASTContext::getPointerDiffType() const { - return getFromTargetType(Target->getPtrDiffType(0)); + return getFromTargetType(Target->getPtrDiffType(LangAS::Default)); } /// Return the unique unsigned counterpart of "ptrdiff_t" /// integer type. The standard (C11 7.21.6.1p7) refers to this type /// in the definition of %tu format specifier. QualType ASTContext::getUnsignedPointerDiffType() const { - return getFromTargetType(Target->getUnsignedPtrDiffType(0)); + return getFromTargetType(Target->getUnsignedPtrDiffType(LangAS::Default)); } /// Return the unique type for "pid_t" defined in Index: clang/include/clang/Basic/TargetInfo.h =================================================================== --- clang/include/clang/Basic/TargetInfo.h +++ clang/include/clang/Basic/TargetInfo.h @@ -357,10 +357,11 @@ IntType getUIntMaxType() const { return getCorrespondingUnsignedType(IntMaxType); } - IntType getPtrDiffType(unsigned AddrSpace) const { - return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); + IntType getPtrDiffType(LangAS AddrSpace) const { + return AddrSpace == LangAS::Default ? PtrDiffType + : getPtrDiffTypeV(AddrSpace); } - IntType getUnsignedPtrDiffType(unsigned AddrSpace) const { + IntType getUnsignedPtrDiffType(LangAS AddrSpace) const { return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace)); } IntType getIntPtrType() const { return IntPtrType; } @@ -438,11 +439,13 @@ /// Return the width of pointers on this target, for the /// specified address space. - uint64_t getPointerWidth(unsigned AddrSpace) const { - return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); + uint64_t getPointerWidth(LangAS AddrSpace) const { + return AddrSpace == LangAS::Default ? PointerWidth + : getPointerWidthV(AddrSpace); } - uint64_t getPointerAlign(unsigned AddrSpace) const { - return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); + uint64_t getPointerAlign(LangAS AddrSpace) const { + return AddrSpace == LangAS::Default ? PointerAlign + : getPointerAlignV(AddrSpace); } /// Return the maximum width of pointers on this target. @@ -604,7 +607,8 @@ /// Determine whether the __int128 type is supported on this target. virtual bool hasInt128Type() const { - return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128; + return (getPointerWidth(LangAS::Default) >= 64) || + getTargetOpts().ForceEnableInt128; } // FIXME /// Determine whether the _BitInt type is supported on this target. This @@ -822,7 +826,9 @@ unsigned getProgramAddressSpace() const { return ProgramAddrSpace; } // Return the size of unwind_word for this target. - virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); } + virtual unsigned getUnwindWordWidth() const { + return getPointerWidth(LangAS::Default); + } /// Return the "preferred" register width on this target. virtual unsigned getRegisterWidth() const { @@ -1485,6 +1491,11 @@ } const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; } + unsigned getTargetAddressSpace(LangAS AS) const { + if (isTargetAddressSpace(AS)) + return toTargetAddressSpace(AS); + return getAddressSpaceMap()[(unsigned)AS]; + } /// Map from the address space field in builtin description strings to the /// language address space. @@ -1686,13 +1697,13 @@ protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); - virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { + virtual uint64_t getPointerWidthV(LangAS AddrSpace) const { return PointerWidth; } - virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { + virtual uint64_t getPointerAlignV(LangAS AddrSpace) const { return PointerAlign; } - virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { + virtual enum IntType getPtrDiffTypeV(LangAS AddrSpace) const { return PtrDiffType; } virtual ArrayRef<const char *> getGCCRegNames() const = 0;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits