[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 Sep 28 17:29:42 PDT 2021
akhuang created this revision.
akhuang added a reviewer: aaron.ballman.
akhuang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
We're currently using address spaces to implement __ptr32/__ptr64 attributes;
this patch fixes a bug where clang doesn't allow types with different pointer
size attributes to be compared.
Fixes https://bugs.llvm.org/show_bug.cgi?id=51889
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110670
Files:
clang/lib/Sema/SemaExprCXX.cpp
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/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.375748.patch
Type: text/x-patch
Size: 1665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210929/3f88af4e/attachment-0001.bin>
More information about the cfe-commits
mailing list