[clang] a76448c - [Clang] Fix replaceability/relocatability computation (#145655)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 25 08:49:19 PDT 2025
Author: Corentin Jabot
Date: 2025-06-25T17:49:15+02:00
New Revision: a76448c27de2fc110c0fe2dac9120d225aee6d39
URL: https://github.com/llvm/llvm-project/commit/a76448c27de2fc110c0fe2dac9120d225aee6d39
DIFF: https://github.com/llvm/llvm-project/commit/a76448c27de2fc110c0fe2dac9120d225aee6d39.diff
LOG: [Clang] Fix replaceability/relocatability computation (#145655)
for eligible classes with user provided constructor or `operator=`
Fixes #144232
Added:
Modified:
clang/lib/Sema/SemaTypeTraits.cpp
clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index c8a764d19c3d5..a233cb6e912f4 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -121,7 +121,7 @@ static bool hasSuitableConstructorForRelocation(Sema &SemaRef,
CXXMethodDecl *Decl =
LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false);
- return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}
@@ -137,7 +137,7 @@ static bool hasSuitableMoveAssignmentOperatorForRelocation(
if (!Decl)
return false;
- return Decl && Decl->isUserProvided() == AllowUserDefined &&
+ return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}
diff --git a/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp b/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
index 7152a5937d9b7..6f4003f525930 100644
--- a/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
+++ b/clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
@@ -410,3 +410,39 @@ C& C::operator=(const C&) = default;
static_assert (!__builtin_is_cpp_trivially_relocatable(C));
static_assert (!__builtin_is_replaceable(C));
}
+
+namespace GH144232 {
+
+struct E trivially_relocatable_if_eligible replaceable_if_eligible {
+ E (E &&);
+ E &operator= (E &&) = default;
+};
+
+struct F trivially_relocatable_if_eligible replaceable_if_eligible {
+ F (F &&) = default;
+ F &operator= (F &&);
+};
+
+struct G trivially_relocatable_if_eligible replaceable_if_eligible { G (G const &) = default; };
+
+struct I trivially_relocatable_if_eligible replaceable_if_eligible { I &operator= (const I &) = default; };
+
+struct J trivially_relocatable_if_eligible replaceable_if_eligible { J (J const &); };
+struct K trivially_relocatable_if_eligible replaceable_if_eligible { K (K const &); };
+
+
+
+static_assert (__builtin_is_replaceable (E));
+static_assert (__builtin_is_cpp_trivially_relocatable(E));
+static_assert (__builtin_is_replaceable (F));
+static_assert (__builtin_is_cpp_trivially_relocatable(F));
+static_assert (__builtin_is_replaceable (G));
+static_assert (__builtin_is_cpp_trivially_relocatable(G));
+static_assert (__builtin_is_replaceable (I));
+static_assert (__builtin_is_cpp_trivially_relocatable(I));
+static_assert (__builtin_is_replaceable (J));
+static_assert (__builtin_is_cpp_trivially_relocatable(J));
+static_assert (__builtin_is_replaceable (K));
+static_assert (__builtin_is_cpp_trivially_relocatable(K));
+
+}
More information about the cfe-commits
mailing list