diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -11959,8 +11959,13 @@ } 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 --- /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