[clang] [Clang] Fix replaceability/relocatability computation (PR #145655)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 25 02:12:59 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Corentin Jabot (cor3ntin)
<details>
<summary>Changes</summary>
for eligible classes with user provided constructor or `operator=`
Fixes #<!-- -->144232
---
Full diff: https://github.com/llvm/llvm-project/pull/145655.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaTypeTraits.cpp (+2-2)
- (modified) clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp (+36)
``````````diff
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 4dbb2450857e0..354816a8e0805 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));
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/145655
More information about the cfe-commits
mailing list