Fix address space for function pointers with qualifier

This patch fixes a bug introduced in commit 4eaf5846d0. Commit
4eaf5846d0 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
This commit is contained in:
Elizabeth Andrews 2022-02-04 15:45:35 -08:00
parent fc6bee1c11
commit ed5b42b741
2 changed files with 17 additions and 2 deletions

View File

@ -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 {

View File

@ -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