[PATCH] D119045: Fix address space for function types with AS qualifier

Elizabeth Andrews via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 4 16:07:34 PST 2022


eandrews created this revision.
eandrews added reviewers: rjmccall, dylanmckay, bader.
eandrews requested review of this revision.

This patch fixes a bug introduced in commit 4eaf5846d0e7 <https://reviews.llvm.org/rG4eaf5846d0e738264d9328b4a919bc352ea83b7a> - https://reviews.llvm.org/D111566

Commit 4eaf5846d0e7 <https://reviews.llvm.org/rG4eaf5846d0e738264d9328b4a919bc352ea83b7a> 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.


https://reviews.llvm.org/D119045

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/address-space-ptr32.c


Index: clang/test/CodeGen/address-space-ptr32.c
===================================================================
--- /dev/null
+++ 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() {
+  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
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11959,8 +11959,11 @@
 }
 
 unsigned ASTContext::getTargetAddressSpace(QualType T) const {
-  return T->isFunctionType() ? getTargetInfo().getProgramAddressSpace()
-                             : getTargetAddressSpace(T.getQualifiers());
+  // For function type, return program address space, unless
+  // type has address space qualifier
+  return T->isFunctionType() && !T.hasAddressSpace()
+             ? getTargetInfo().getProgramAddressSpace()
+             : getTargetAddressSpace(T.getQualifiers());
 }
 
 unsigned ASTContext::getTargetAddressSpace(Qualifiers Q) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119045.406124.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220205/29a7619f/attachment.bin>


More information about the cfe-commits mailing list