[clang] [AMDGPU] Do not allow the region address space to be converted to generic (PR #117171)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 21 06:57:13 PST 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/117171
Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.
>From d980715272ecdc028f0f9ccdc24417c270b01dd2 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 21 Nov 2024 08:55:38 -0600
Subject: [PATCH] [AMDGPU] Do not allow the region address space to be
converted to generic
Summary:
Previous changes relaxed the address space rules based on what the
target says about them. This accidentally included the AS(2) region as
convertible to generic. Simply check for AS(2) and reject it.
---
clang/lib/Basic/Targets/AMDGPU.h | 3 ++-
clang/test/Sema/amdgcn-address-spaces.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index db7a095ba2a4fe..ea4189cdea47da 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -120,7 +120,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
toTargetAddressSpace(A) == llvm::AMDGPUAS::FLAT_ADDRESS)) &&
isTargetAddressSpace(B) &&
toTargetAddressSpace(B) >= llvm::AMDGPUAS::FLAT_ADDRESS &&
- toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS);
+ toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS &&
+ toTargetAddressSpace(B) != llvm::AMDGPUAS::REGION_ADDRESS);
}
uint64_t getMaxPointerWidth() const override {
diff --git a/clang/test/Sema/amdgcn-address-spaces.c b/clang/test/Sema/amdgcn-address-spaces.c
index 50c12993ac69b8..70545db920c807 100644
--- a/clang/test/Sema/amdgcn-address-spaces.c
+++ b/clang/test/Sema/amdgcn-address-spaces.c
@@ -9,7 +9,7 @@
#define _AS999 __attribute__((address_space(999)))
void *p1(void _AS1 *p) { return p; }
-void *p2(void _AS2 *p) { return p; }
+void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void *' from a function with result type 'void *' changes address space of pointer}}
void *p3(void _AS3 *p) { return p; }
void *p4(void _AS4 *p) { return p; }
void *p5(void _AS5 *p) { return p; }
More information about the cfe-commits
mailing list