diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/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 { diff --git a/clang/test/Sema/MicrosoftExtensions.cpp b/clang/test/Sema/MicrosoftExtensions.cpp new file mode 100644 --- /dev/null +++ b/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); +}