================
@@ -174,5 +160,52 @@ TEST_F(CopyProfStateTest,
DISABLED_TemporaryObjectInDtorDoesNotSuppressReport) {
EXPECT_TRUE(__copyprof_state.is_transitive_copy);
}
+// Likewise for a temporary that the d'tor copy-constructs, e.g. from a member.
+TEST_F(CopyProfStateTest, CopiedTemporaryInDtorDoesNotSuppressReport) {
+ char obj[32] = {0};
+ char source_obj[32] = {0};
+ char temp[32] = {0};
+
+ __copyprof_copy_ctor_enter_callback(obj, source_obj, sizeof(obj));
+ __copyprof_copy_ctor_exit_callback(obj, source_obj, sizeof(obj));
+ // Memory occupied by `temp` is not a copy.
+ MarkApplicationMemory(temp, sizeof(temp), /*is_copy=*/false);
+
+ __copyprof_dtor_enter_callback(obj, sizeof(obj));
+ __copyprof_copy_ctor_enter_callback(temp, obj, sizeof(temp));
+ __copyprof_copy_ctor_exit_callback(temp, obj, sizeof(temp));
+ __copyprof_dtor_enter_callback(temp, sizeof(temp));
+ __copyprof_dtor_exit_callback(temp, sizeof(temp));
+ __copyprof_dtor_exit_callback(obj, sizeof(obj));
+ EXPECT_TRUE(__copyprof_state.is_transitive_copy);
+}
+
+// A temporary with a trivial c'tor gets no c'tor callback, so it is not marked
+// as copy when a d'tor creates it. If its d'tor is instrumented, destroying it
+// folds whatever shadow its memory had before into `is_transitive_copy`, which
+// may suppress the report.
+//
+// DISABLED: known limitation. Possible fixes are to also instrument trivial
+// construction, or to skip the fold for objects in the stack frames below the
+// top-level d'tor.
+TEST_F(CopyProfStateTest,
+ DISABLED_TriviallyConstructedTemporaryInDtorDoesNotSuppressReport) {
+ char obj[32] = {0};
+ char source_obj[32] = {0};
+ char temp[32] = {0};
+
+ __copyprof_copy_ctor_enter_callback(obj, source_obj, sizeof(obj));
+ __copyprof_copy_ctor_exit_callback(obj, source_obj, sizeof(obj));
+ // Memory occupied by `temp` is not a copy.
+ MarkApplicationMemory(temp, sizeof(temp), /*is_copy=*/false);
+
+ __copyprof_dtor_enter_callback(obj, sizeof(obj));
+ // `temp` is created without a c'tor callback, then destroyed.
+ __copyprof_dtor_enter_callback(temp, sizeof(temp));
+ __copyprof_dtor_exit_callback(temp, sizeof(temp));
+ __copyprof_dtor_exit_callback(obj, sizeof(obj));
+ EXPECT_TRUE(__copyprof_state.is_transitive_copy);
+}
----------------
newgre wrote:
Yep, added some basic tests.
https://github.com/llvm/llvm-project/pull/232851
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits