[PATCH] D110670: [Sema] Allow comparisons between different ms ptr size address space types.
Amy Huang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 5 10:56:42 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7104e506619: [Sema] Allow comparisons between different ms ptr size address space types. (authored by akhuang).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110670/new/
https://reviews.llvm.org/D110670
Files:
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGen/ms-mixed-ptr-sizes.c
clang/test/Sema/MicrosoftExtensions.cpp
Index: clang/test/Sema/MicrosoftExtensions.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p32s,
+ int *__ptr64 p64) {
+ return (p32u == p32s) +
+ (p32u == p64) +
+ (p32s == p64);
+}
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===================================================================
--- clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefix=X64
-// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X64,ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X86,ALL
struct Foo {
int * __ptr32 p32;
@@ -47,3 +47,39 @@
f->p32 = (int * __ptr32)i;
use_foo(f);
}
+
+int test_compare1(int *__ptr32 __uptr i, int *__ptr64 j) {
+ // ALL-LABEL: define dso_local i32 @test_compare1
+ // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(271)*
+ // X64: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+ // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32 addrspace(271)*
+ // X86: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+ return (i == j);
+}
+
+int test_compare2(int *__ptr32 __sptr i, int *__ptr64 j) {
+ // ALL-LABEL: define dso_local i32 @test_compare2
+ // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(270)*
+ // X64: %cmp = icmp eq i32 addrspace(270)* %{{.+}}, %i
+ // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32*
+ // X86: %cmp = icmp eq i32* %{{.+}}, %i
+ return (i == j);
+}
+
+int test_compare3(int *__ptr32 __uptr i, int *__ptr64 j) {
+ // ALL-LABEL: define dso_local i32 @test_compare3
+ // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
+ // X64: %cmp = icmp eq i32* %{{.+}}, %j
+ // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
+ // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+ return (j == i);
+}
+
+int test_compare4(int *__ptr32 __sptr i, int *__ptr64 j) {
+ // ALL-LABEL: define dso_local i32 @test_compare4
+ // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
+ // X64: %cmp = icmp eq i32* %{{.+}}, %j
+ // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
+ // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+ return (j == i);
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6674,8 +6674,15 @@
} else if (Steps.size() == 1) {
bool MaybeQ1 = Q1.isAddressSpaceSupersetOf(Q2);
bool MaybeQ2 = Q2.isAddressSpaceSupersetOf(Q1);
- if (MaybeQ1 == MaybeQ2)
- return QualType(); // No unique best address space.
+ if (MaybeQ1 == MaybeQ2) {
+ // Exception for ptr size address spaces. Should be able to choose
+ // either address space during comparison.
+ if (isPtrSizeAddressSpace(Q1.getAddressSpace()) ||
+ isPtrSizeAddressSpace(Q2.getAddressSpace()))
+ MaybeQ1 = true;
+ else
+ return QualType(); // No unique best address space.
+ }
Quals.setAddressSpace(MaybeQ1 ? Q1.getAddressSpace()
: Q2.getAddressSpace());
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110670.377298.patch
Type: text/x-patch
Size: 3986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211005/6625f570/attachment.bin>
More information about the cfe-commits
mailing list