From a602f76a2406cc3edd6b297ede3583b26513a34c Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 18 Nov 2022 12:14:00 +0000 Subject: [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 --- clang/lib/Frontend/InitPreprocessor.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'clang/lib/Frontend/InitPreprocessor.cpp') diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 69480c9..3e33d93 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -948,14 +948,14 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // 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 @@ static void InitializePredefinedMacros(const TargetInfo &TI, 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_"); -- cgit v1.1