Author: Elizabeth Andrews Date: 2022-02-07T12:53:24-08:00 New Revision: ed5b42b741881a0a94e65999f0c785ec53b46511
URL: https://github.com/llvm/llvm-project/commit/ed5b42b741881a0a94e65999f0c785ec53b46511 DIFF: https://github.com/llvm/llvm-project/commit/ed5b42b741881a0a94e65999f0c785ec53b46511.diff LOG: Fix address space for function pointers with qualifier This patch fixes a bug introduced in commit 4eaf5846d0e7. Commit 4eaf5846d0e7 sets address space of function type as program address space unconditionally. This breaks types which have address space qualifiers. E.g. __ptr32. This patch fixes the bug by using address space qualifiers if present. Differential Revision: https://reviews.llvm.org/D119045 Added: clang/test/CodeGen/address-space-ptr32.c Modified: clang/lib/AST/ASTContext.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 5fa2d46de89b2..f2ac57465398b 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -11959,8 +11959,13 @@ uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const { } unsigned ASTContext::getTargetAddressSpace(QualType T) const { - return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace() - : getTargetAddressSpace(T.getQualifiers()); + // Return the address space for the type. If the type is a + // function type without an address space qualifier, the + // program address space is used. Otherwise, the target picks + // the best address space based on the type information + return T->isFunctionType() && !T.hasAddressSpace() + ? getTargetInfo().getProgramAddressSpace() + : getTargetAddressSpace(T.getQualifiers()); } unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const { diff --git a/clang/test/CodeGen/address-space-ptr32.c b/clang/test/CodeGen/address-space-ptr32.c new file mode 100644 index 0000000000000..7684fdc487d49 --- /dev/null +++ b/clang/test/CodeGen/address-space-ptr32.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s | FileCheck %s + +int foo(void) { + int (*__ptr32 a)(int); + return sizeof(a); +} + +// CHECK: define dso_local i32 @foo +// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4 +// CHECK: ret i32 4 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits