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/Frontend/InitPreprocessor.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/Frontend/InitPreprocessor.cpp')
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
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_"); |