Skip to content

Commit ed5b42b

Browse files
Fix address space for function pointers with qualifier
This patch fixes a bug introduced in commit 4eaf584. Commit 4eaf584 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
1 parent fc6bee1 commit ed5b42b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11959,8 +11959,13 @@ uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const {
1195911959
}
1196011960

1196111961
unsigned ASTContext::getTargetAddressSpace(QualType T) const {
11962-
return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
11963-
: getTargetAddressSpace(T.getQualifiers());
11962+
// Return the address space for the type. If the type is a
11963+
// function type without an address space qualifier, the
11964+
// program address space is used. Otherwise, the target picks
11965+
// the best address space based on the type information
11966+
return T->isFunctionType() && !T.hasAddressSpace()
11967+
? getTargetInfo().getProgramAddressSpace()
11968+
: getTargetAddressSpace(T.getQualifiers());
1196411969
}
1196511970

1196611971
unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm < %s | FileCheck %s
2+
3+
int foo(void) {
4+
int (*__ptr32 a)(int);
5+
return sizeof(a);
6+
}
7+
8+
// CHECK: define dso_local i32 @foo
9+
// CHECK: %a = alloca i32 (i32) addrspace(270)*, align 4
10+
// CHECK: ret i32 4

0 commit comments

Comments
 (0)