[clang] cf51876 - [clang][MSExtentions] Fix invalid overload failure about the loss of `__unaligned` qualifier (#65248)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 21:22:11 PDT 2023


Author: Takuya Shimizu
Date: 2023-09-08T13:22:07+09:00
New Revision: cf51876dd90968787692ef77b4de05c36c730936

URL: https://github.com/llvm/llvm-project/commit/cf51876dd90968787692ef77b4de05c36c730936
DIFF: https://github.com/llvm/llvm-project/commit/cf51876dd90968787692ef77b4de05c36c730936.diff

LOG: [clang][MSExtentions] Fix invalid overload failure about the loss of `__unaligned` qualifier (#65248)

Loss of `__unaligned` qualifier does not invalidate overload candidates.
This fixes a regression reported in https://reviews.llvm.org/D153690

Reviewed By: cor3ntin, AaronBallman
PR: https://github.com/llvm/llvm-project/pull/65248

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaOverload.cpp
    clang/test/SemaCXX/MicrosoftExtensions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1ac0cb2fac72a79..28a6ec0acd409b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -216,6 +216,8 @@ Bug Fixes in This Version
   local structs.
 - Correctly parse non-ascii identifiers that appear immediately after a line splicing
   (`#65156 <https://github.com/llvm/llvm-project/issues/65156>`_`)
+- Clang no longer considers the loss of ``__unaligned`` qualifier from objects as
+  an invalid conversion during method function overload resolution.
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d69b339306f0060..3ba7266122e4c0c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5556,9 +5556,11 @@ TryObjectArgumentInitialization(Sema &S, SourceLocation Loc, QualType FromType,
 
   // First check the qualifiers.
   QualType FromTypeCanon = S.Context.getCanonicalType(FromType);
-  if (ImplicitParamType.getCVRQualifiers()
-                                    != FromTypeCanon.getLocalCVRQualifiers() &&
-      !ImplicitParamType.isAtLeastAsQualifiedAs(FromTypeCanon)) {
+  // MSVC ignores __unaligned qualifier for overload candidates; do the same.
+  if (ImplicitParamType.getCVRQualifiers() !=
+          FromTypeCanon.getLocalCVRQualifiers() &&
+      !ImplicitParamType.isAtLeastAsQualifiedAs(
+          withoutUnaligned(S.Context, FromTypeCanon))) {
     ICS.setBad(BadConversionSequence::bad_qualifiers,
                FromType, ImplicitParamType);
     return ICS;

diff  --git a/clang/test/SemaCXX/MicrosoftExtensions.cpp b/clang/test/SemaCXX/MicrosoftExtensions.cpp
index 960030d44f0c155..7286217b1644f3e 100644
--- a/clang/test/SemaCXX/MicrosoftExtensions.cpp
+++ b/clang/test/SemaCXX/MicrosoftExtensions.cpp
@@ -589,6 +589,18 @@ namespace PR42089 {
   __attribute__((nothrow)) void S::Bar(){}
 }
 
+namespace UnalignedConv {
+struct S {
+  bool operator==(int) const;
+};
+
+int func() {
+  S __unaligned s;
+  return s == 42;
+}
+}
+
+
 #elif TEST2
 
 // Check that __unaligned is not recognized if MS extensions are not enabled


        


More information about the cfe-commits mailing list