From 5f2f6f681bb51cccf56f68060f158e31d58c7524 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 14 Nov 2026 18:40:32 +0000 Subject: [PATCH 01/11] Add basic.def.odr tests --- .../basic.def.odr/p11-discarded-statement.cpp | 26 ++++++++++++++ ...nline-undefined-in-discarded-statement.cpp | 22 ++++++++++++ .../p13-pointer-to-incomplete-class.cpp | 18 ++++++++++ .../CMakeLists.txt | 5 +++ .../a.cpp | 11 ++++++ .../b.cpp | 5 +++ .../p14-unnamed-enumeration-in-two-files/h.h | 10 ++++++ .../CMakeLists.txt | 5 +++ .../a.cpp | 10 ++++++ .../b.cpp | 7 ++++ .../h.h | 14 ++++++++ .../p15-function-template/CMakeLists.txt | 5 +++ .../basic.def.odr/p15-function-template/a.cpp | 16 +++++++++ .../basic.def.odr/p15-function-template/b.cpp | 5 +++ .../basic.def.odr/p15-function-template/h.h | 16 +++++++++ .../p15-inline-function/CMakeLists.txt | 5 +++ .../basic.def.odr/p15-inline-function/a.cpp | 17 ++++++++++ .../basic.def.odr/p15-inline-function/b.cpp | 5 +++ .../basic.def.odr/p15-inline-function/h.h | 14 ++++++++ .../p15-inline-variable/CMakeLists.txt | 5 +++ .../basic.def.odr/p15-inline-variable/a.cpp | 13 +++++++ .../basic.def.odr/p15-inline-variable/b.cpp | 5 +++ .../basic.def.odr/p15-inline-variable/h.h | 12 +++++++ .../CMakeLists.txt | 5 +++ .../p16-lambda-in-inline-function/a.cpp | 15 ++++++++ .../p16-lambda-in-inline-function/b.cpp | 3 ++ .../p16-lambda-in-inline-function/h.h | 19 +++++++++++ .../basic/basic.def.odr/p3.2-subscript.cpp | 15 ++++++++ .../basic.def.odr/p3.3-member-access.cpp | 15 ++++++++ .../basic.def.odr/p3.5-pointer-to-member.cpp | 16 +++++++++ .../basic/basic.def.odr/p3.7-conditional.cpp | 17 ++++++++++ tests/std/basic/basic.def.odr/p3.8-comma.cpp | 19 +++++++++++ .../p4.1-pure-virtual-member-pointer.cpp | 25 ++++++++++++++ .../p4.1-pure-virtual-qualified-call.cpp | 32 +++++++++++++++++ .../p4.1-pure-virtual-without-definition.cpp | 23 +++++++++++++ .../p5.1-constant-reference-in-lambda.cpp | 19 +++++++++++ .../p5.2-address-of-constant-is-odr-use.cpp | 13 +++++++ .../p5.2-class-object-is-odr-used.cpp | 17 ++++++++++ ...5.2-constant-in-lambda-without-capture.cpp | 11 ++++++ .../p5.3-discarded-value-in-lambda.cpp | 16 +++++++++ .../p6-evaluated-binding-is-captured.cpp | 24 +++++++++++++ ...6-unevaluated-binding-needs-no-capture.cpp | 22 ++++++++++++ .../p7-member-access-captures-this.cpp | 31 +++++++++++++++++ .../p7-unevaluated-this-needs-no-capture.cpp | 22 ++++++++++++ ...8-unevaluated-call-needs-no-definition.cpp | 28 +++++++++++++++ .../p9-destructor-not-potentially-invoked.cpp | 19 +++++++++++ .../p9-unused-implicit-assignment.cpp | 25 ++++++++++++++ tests/std/support/lifetime-tracked.h | 34 +++++++++++++++++++ 48 files changed, 736 insertions(+) create mode 100644 tests/std/basic/basic.def.odr/p11-discarded-statement.cpp create mode 100644 tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp create mode 100644 tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/h.h create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/h.h create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/h.h create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/h.h create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/h.h create mode 100644 tests/std/basic/basic.def.odr/p3.2-subscript.cpp create mode 100644 tests/std/basic/basic.def.odr/p3.3-member-access.cpp create mode 100644 tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp create mode 100644 tests/std/basic/basic.def.odr/p3.7-conditional.cpp create mode 100644 tests/std/basic/basic.def.odr/p3.8-comma.cpp create mode 100644 tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp create mode 100644 tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp create mode 100644 tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp create mode 100644 tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp create mode 100644 tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp create mode 100644 tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp create mode 100644 tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp create mode 100644 tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp create mode 100644 tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp create mode 100644 tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp create mode 100644 tests/std/support/lifetime-tracked.h diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp new file mode 100644 index 0000000000..2a3978690a --- /dev/null +++ b/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp @@ -0,0 +1,26 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/11: a definition is required only for functions +// odr-used outside of a discarded statement. undefined() is called only in a +// discarded statement, so it is never defined and never runs. +#include "../../support/lifetime-tracked.h" +#include + +static int else_runs; + +LifetimeTracked undefined(); + +void g() { + if constexpr (false) { + undefined().use(); + } else { + ++else_runs; + } +} + +int main() { + g(); + assert(else_runs == 1); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp new file mode 100644 index 0000000000..d9c6c5374d --- /dev/null +++ b/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp @@ -0,0 +1,22 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/12: an inline function needs a reachable definition +// only where it is odr-used outside of a discarded statement. f is used only in +// a discarded statement, so it is never defined and never runs. +#include + +static int g_calls; + +inline void f(); + +void g() { + if constexpr (false) { + f(); + } + ++g_calls; +} + +int main() { + g(); + assert(g_calls == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp b/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp new file mode 100644 index 0000000000..7ddee346b5 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp @@ -0,0 +1,18 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/13, Example 4: X is never defined. Forming, copying and +// comparing pointers to X does not require X to be complete. +#include + +struct X; +struct X *x1; +X *x2; + +X *identity(X *p) { return p; } + +int main() { + assert(x1 == nullptr); + assert(identity(x2) == x1); + X **pp = &x1; + assert(*pp == nullptr); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt new file mode 100644 index 0000000000..684947285c --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p14_unnamed_enumeration_in_two_files LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp new file mode 100644 index 0000000000..8c69b82cd4 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp @@ -0,0 +1,11 @@ +#include "h.h" +#include + +int main() { + current = A; + assert(current == 1); + b_set_b(); + assert(current == B); + assert(current == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp new file mode 100644 index 0000000000..ddbaf5a11b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp @@ -0,0 +1,5 @@ +#include "h.h" + +decltype(A) current; + +void b_set_b() { current = B; } diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h new file mode 100644 index 0000000000..610ca56f9e --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h @@ -0,0 +1,10 @@ +// N4950 [basic.def.odr]/14: an unnamed enumeration may be defined in several +// translation units if every definition satisfies the requirements; the +// definitions then denote one type, so `current` is one object of that type. +#pragma once + +enum { A = 1, B }; + +extern decltype(A) current; + +void b_set_b(); diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/CMakeLists.txt b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/CMakeLists.txt new file mode 100644 index 0000000000..a572cd5054 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p14_5_1_inline_function_reads_per_file_constant LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp new file mode 100644 index 0000000000..93c701864a --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp @@ -0,0 +1,10 @@ +#include "h.h" +#include + +int main() { + assert(&factor != b_factor_address()); + assert(&scaled == b_scaled_address()); + assert(scaled(2) == 6); + assert(b_scaled(2) == 6); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/b.cpp b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/b.cpp new file mode 100644 index 0000000000..848465ce25 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/b.cpp @@ -0,0 +1,7 @@ +#include "h.h" + +const int *b_factor_address() { return &factor; } + +int (*b_scaled_address())(int) { return &scaled; } + +int b_scaled(int v) { return scaled(v); } diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/h.h b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/h.h new file mode 100644 index 0000000000..2900f41af9 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/h.h @@ -0,0 +1,14 @@ +// N4950 [basic.def.odr]/14.5.1: an inline function defined in several +// translation units may name a const object with internal linkage, although +// that is a different object in each translation unit, provided the object has +// the same value everywhere and is only read by value. factor is such an +// object: each file has its own, and scaled is still one function. +#pragma once + +const int factor = 3; + +inline int scaled(int v) { return v * factor; } + +const int *b_factor_address(); +int (*b_scaled_address())(int); +int b_scaled(int v); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/CMakeLists.txt b/tests/std/basic/basic.def.odr/p15-function-template/CMakeLists.txt new file mode 100644 index 0000000000..84598b92bd --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p15_function_template LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp new file mode 100644 index 0000000000..056b489401 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp @@ -0,0 +1,16 @@ +#include "h.h" +#include + +AssertsDtorCountAtExit check{2}; + +int main() { + assert(LifetimeTracked::ctorCount == 0); + assert(count() == 1); + assert(b_count_int() == 2); + assert(count() == 3); + assert(LifetimeTracked::ctorCount == 1); + assert(count() == 1); + assert(b_count_long() == 2); + assert(LifetimeTracked::ctorCount == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p15-function-template/b.cpp b/tests/std/basic/basic.def.odr/p15-function-template/b.cpp new file mode 100644 index 0000000000..1068ec9648 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/b.cpp @@ -0,0 +1,5 @@ +#include "h.h" + +int b_count_int() { return count(); } + +int b_count_long() { return count(); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/h.h b/tests/std/basic/basic.def.odr/p15-function-template/h.h new file mode 100644 index 0000000000..59a1696008 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/h.h @@ -0,0 +1,16 @@ +// N4950 [basic.def.odr]/15: a template defined in several translation units +// behaves as a single entity, so the same specialization instantiated in two +// translation units has one set of static local variables, constructed once and +// destroyed once. Different specializations have their own. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +template int count() { + static LifetimeTracked t; + static int n = 0; + return ++n; +} + +int b_count_int(); +int b_count_long(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/CMakeLists.txt b/tests/std/basic/basic.def.odr/p15-inline-function/CMakeLists.txt new file mode 100644 index 0000000000..0c4b775c56 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p15_inline_function LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp new file mode 100644 index 0000000000..9e4bd67adf --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp @@ -0,0 +1,17 @@ +#include "h.h" +#include + +AssertsDtorCountAtExit check{1}; + +int main() { + assert(LifetimeTracked::ctorCount == 0); + instance().use(); + b_use(); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 2); + assert(instance().uses == 2); + assert(&instance() == b_address()); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/b.cpp b/tests/std/basic/basic.def.odr/p15-inline-function/b.cpp new file mode 100644 index 0000000000..1316ce0053 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/b.cpp @@ -0,0 +1,5 @@ +#include "h.h" + +void b_use() { instance().use(); } + +LifetimeTracked *b_address() { return &instance(); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/h.h b/tests/std/basic/basic.def.odr/p15-inline-function/h.h new file mode 100644 index 0000000000..1b8d0b388b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/h.h @@ -0,0 +1,14 @@ +// N4950 [basic.def.odr]/15: an inline function defined in several translation +// units behaves as a single entity with a single definition: one address and +// one static local variable, constructed once and destroyed once. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +inline LifetimeTracked &instance() { + static LifetimeTracked t; + return t; +} + +void b_use(); +LifetimeTracked *b_address(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/CMakeLists.txt b/tests/std/basic/basic.def.odr/p15-inline-variable/CMakeLists.txt new file mode 100644 index 0000000000..1c17a0355c --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p15_inline_variable LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp b/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp new file mode 100644 index 0000000000..4a0ec83010 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp @@ -0,0 +1,13 @@ +#include "h.h" +#include + +int main() { + shared.use(); + b_use(); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 2); + assert(shared.uses == 2); + assert(&shared == b_address()); + assert(LifetimeTracked::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/b.cpp b/tests/std/basic/basic.def.odr/p15-inline-variable/b.cpp new file mode 100644 index 0000000000..4e1ec9898c --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/b.cpp @@ -0,0 +1,5 @@ +#include "h.h" + +void b_use() { shared.use(); } + +LifetimeTracked *b_address() { return &shared; } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/h.h b/tests/std/basic/basic.def.odr/p15-inline-variable/h.h new file mode 100644 index 0000000000..c94ad19116 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/h.h @@ -0,0 +1,12 @@ +// N4950 [basic.def.odr]/15: an inline variable defined in several translation +// units behaves as a single entity: one object with one address, constructed +// once and destroyed once. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +inline AssertsDtorCountAtExit check{1}; +inline LifetimeTracked shared; + +void b_use(); +LifetimeTracked *b_address(); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/CMakeLists.txt b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/CMakeLists.txt new file mode 100644 index 0000000000..bfe635d203 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p16_lambda_in_inline_function LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp new file mode 100644 index 0000000000..309d261209 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp @@ -0,0 +1,15 @@ +#include "h.h" +#include + +AssertsDtorCountAtExit check{1}; + +int main() { + assert(LifetimeTracked::ctorCount == 0); + f(true, nullptr); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 1); + b_call(); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/b.cpp b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/b.cpp new file mode 100644 index 0000000000..b79c8df557 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/b.cpp @@ -0,0 +1,3 @@ +#include "h.h" + +void b_call() { f(true, nullptr); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/h.h b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/h.h new file mode 100644 index 0000000000..666093e554 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/h.h @@ -0,0 +1,19 @@ +// N4950 [basic.def.odr]/16, Example 6: f is an inline function containing a +// lambda-expression. Defined in several translation units, it behaves as one +// definition, so the lambda inside it is one closure type with one static +// local variable. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +inline void f(bool cond, void (*p)()) { + if (cond) + f(false, [] { + static LifetimeTracked local; + local.use(); + }); + else + p(); +} + +void b_call(); diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp new file mode 100644 index 0000000000..528f51eb49 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp @@ -0,0 +1,15 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation +// with an array operand are those of the operand. Reading arr[1].m does not +// odr-use arr, so [=] does not capture it. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + constexpr HasConstexprCtor arr[2] = {3, 4}; + auto f = [=] { return arr[1].m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 4); + assert(HasConstexprCtor::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp new file mode 100644 index 0000000000..ee900024d5 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp @@ -0,0 +1,15 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/3.3: the potential results of E1.E2 naming a non-static +// data member are those of E1. Reading k.m does not odr-use k, so [=] does not +// capture it. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + constexpr HasConstexprCtor k{5}; + auto f = [=] { return k.m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp new file mode 100644 index 0000000000..dd9c716935 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp @@ -0,0 +1,16 @@ +// XFAIL: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/3.5: the potential results of E1.*E2 are those of E1. +// Reading k.*pm does not odr-use k, so [=] does not capture it. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + constexpr HasConstexprCtor k{5}; + constexpr int HasConstexprCtor::*pm = &HasConstexprCtor::m; + auto f = [=] { return k.*pm; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp new file mode 100644 index 0000000000..ae24ffc484 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp @@ -0,0 +1,17 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/3.7: the potential results of a glvalue conditional +// expression are those of its second and third operands. Neither k1 nor k2 is +// odr-used, so [=] captures neither. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + constexpr HasConstexprCtor k1{7}; + constexpr HasConstexprCtor k2{9}; + auto f = [=](bool b) { return (b ? k1 : k2).m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f(true) == 7); + assert(f(false) == 9); + assert(HasConstexprCtor::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p3.8-comma.cpp b/tests/std/basic/basic.def.odr/p3.8-comma.cpp new file mode 100644 index 0000000000..905cac761c --- /dev/null +++ b/tests/std/basic/basic.def.odr/p3.8-comma.cpp @@ -0,0 +1,19 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/3.8: the potential results of a comma expression are +// those of its right operand. k is not odr-used, so [=] does not capture it; +// the left operand is still evaluated. +#include "../../support/lifetime-tracked.h" +#include + +static int left; + +int main() { + constexpr HasConstexprCtor k{5}; + auto f = [=] { return (++left, k).m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(left == 0); + assert(f() == 5); + assert(left == 1); + assert(HasConstexprCtor::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp new file mode 100644 index 0000000000..6f468ecdfa --- /dev/null +++ b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp @@ -0,0 +1,25 @@ +// XFAIL: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/4.1: forming a pointer to member does not name a pure +// virtual function. HasPureVirtual::f is never defined; the call through the +// pointer to member runs the override. +#include + +static int derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { ++derived_calls; } +}; + +int main() { + void (HasPureVirtual::*pm)() = &HasPureVirtual::f; + OverridesPureVirtual d; + HasPureVirtual *p = &d; + (p->*pm)(); + assert(derived_calls == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp new file mode 100644 index 0000000000..a9f5366f52 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp @@ -0,0 +1,32 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/4.1: a pure virtual function is named by an +// id-expression with an explicitly qualified name. HasPureVirtual::f is pure +// but defined; the qualified call runs the base body, not the override. +#include + +static int base_calls, derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +void HasPureVirtual::f() { ++base_calls; } + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { + ++derived_calls; + HasPureVirtual::f(); + } +}; + +int main() { + OverridesPureVirtual d; + HasPureVirtual *p = &d; + p->f(); + assert(derived_calls == 1); + assert(base_calls == 1); + d.HasPureVirtual::f(); + assert(derived_calls == 1); + assert(base_calls == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp new file mode 100644 index 0000000000..4a84943c6b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp @@ -0,0 +1,23 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/4.1: a pure virtual function is not named by a call +// that is not explicitly qualified. HasPureVirtual::f is never defined; the +// virtual call runs the override. +#include + +static int derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { ++derived_calls; } +}; + +int main() { + OverridesPureVirtual d; + HasPureVirtual *p = &d; + p->f(); + assert(derived_calls == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp b/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp new file mode 100644 index 0000000000..2887ef8082 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp @@ -0,0 +1,19 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.1: a reference that is usable in constant expressions +// is not odr-used. [=] therefore does not capture r, and the lambda uses the +// object r refers to. +#include "../../support/lifetime-tracked.h" +#include + +LifetimeTracked global; + +int main() { + constexpr LifetimeTracked &r = global; + auto f = [=] { r.use(); }; + assert(LifetimeTracked::copyCount == 0); + f(); + assert(LifetimeTracked::copyCount == 0); + assert(global.uses == 1); + assert(LifetimeTracked::ctorCount == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp b/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp new file mode 100644 index 0000000000..83d1d2871e --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp @@ -0,0 +1,13 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.2: the exemption requires the lvalue-to-rvalue +// conversion. Taking the address of the constant n odr-uses it, so [=] captures +// a copy, and the address seen inside the lambda is not that of n. +#include + +int main() { + const int n = 5; + auto f = [=] { return &n; }; + assert(f() != &n); + assert(*f() == 5); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp new file mode 100644 index 0000000000..a9489e0466 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp @@ -0,0 +1,17 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.2: the exemption covers only expressions of non-class +// type. Copying the constant k as a whole odr-uses it, so [=] captures it. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + constexpr HasConstexprCtor k{5}; + auto f = [=] { + HasConstexprCtor c = k; + return c.m; + }; + assert(HasConstexprCtor::copyCount == 1); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp b/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp new file mode 100644 index 0000000000..3744c35dd6 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp @@ -0,0 +1,11 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.2: a constant variable of non-class type read by +// value is not odr-used, so the lambda uses n with an empty capture list. +#include + +int main() { + const int n = 5; + auto f = [] { return n; }; + assert(f() == 5); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp b/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp new file mode 100644 index 0000000000..16dde2f168 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp @@ -0,0 +1,16 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.3: a variable named by a discarded-value expression +// to which the lvalue-to-rvalue conversion is not applied is not odr-used, so +// [=] does not capture t. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + LifetimeTracked t; + auto f = [=] { (void)t; }; + assert(LifetimeTracked::copyCount == 0); + f(); + assert(LifetimeTracked::copyCount == 0); + assert(LifetimeTracked::ctorCount == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp new file mode 100644 index 0000000000..73c3b3ad5b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp @@ -0,0 +1,24 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/6: a structured binding is odr-used if it appears as a +// potentially-evaluated expression, so [=] captures a by copy. +#include "../../support/lifetime-tracked.h" +#include + +struct HasTwoMembers { + LifetimeTracked a; + LifetimeTracked b; +}; + +int main() { + HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; + assert(LifetimeTracked::ctorCount == 2); + auto &[a, b] = p; + assert(LifetimeTracked::copyCount == 0); + auto f = [=] { a.use(); }; + assert(LifetimeTracked::copyCount == 1); + f(); + assert(LifetimeTracked::copyCount == 1); + assert(LifetimeTracked::useCount == 1); + assert(p.a.uses == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp new file mode 100644 index 0000000000..96f438dacd --- /dev/null +++ b/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp @@ -0,0 +1,22 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/6: a structured binding is odr-used only if it appears +// as a potentially-evaluated expression. In sizeof it is unevaluated, so [=] +// does not capture a. +#include "../../support/lifetime-tracked.h" +#include + +struct HasTwoMembers { + LifetimeTracked a; + LifetimeTracked b; +}; + +int main() { + HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; + auto &[a, b] = p; + auto f = [=] { return sizeof(a); }; + assert(LifetimeTracked::copyCount == 0); + assert(f() == sizeof(LifetimeTracked)); + assert(LifetimeTracked::copyCount == 0); + assert(LifetimeTracked::useCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp b/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp new file mode 100644 index 0000000000..04bd3be32b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp @@ -0,0 +1,31 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/7: *this is odr-used if this appears as a +// potentially-evaluated expression, including through the implicit +// transformation of a member name. [=] captures this, not the member x, and the +// lambda sees later changes to the object. +#include "../../support/lifetime-tracked.h" +#include + +struct HasMemberUsedInLambda { + LifetimeTracked x; + int n = 1; + auto makeLambda() { + return [=] { + x.use(); + return n; + }; + } +}; + +int main() { + HasMemberUsedInLambda c; + auto f = c.makeLambda(); + assert(LifetimeTracked::copyCount == 0); + assert(f() == 1); + assert(c.x.uses == 1); + c.n = 10; + assert(f() == 10); + assert(c.x.uses == 2); + assert(LifetimeTracked::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp new file mode 100644 index 0000000000..3528d4bcbc --- /dev/null +++ b/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp @@ -0,0 +1,22 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/7: *this is odr-used only if this appears as a +// potentially-evaluated expression. In sizeof the member name is unevaluated, +// so the lambda needs no capture. +#include "../../support/lifetime-tracked.h" +#include + +struct HasMemberUsedInLambda { + LifetimeTracked x; + auto sizer() { + return [] { return sizeof(x); }; + } +}; + +int main() { + HasMemberUsedInLambda c; + auto f = c.sizer(); + assert(f() == sizeof(LifetimeTracked)); + assert(LifetimeTracked::copyCount == 0); + assert(LifetimeTracked::useCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp new file mode 100644 index 0000000000..14e51137e3 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp @@ -0,0 +1,28 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/8: a function is odr-used if it is named by a +// potentially-evaluated expression. make() is named only in unevaluated +// operands, so it is never defined; noisy() is defined, but an unevaluated call +// does not run it. +#include "../../support/lifetime-tracked.h" +#include + +static int noisy_calls; + +LifetimeTracked make(); + +int noisy() { + ++noisy_calls; + return 1; +} + +int main() { + assert(sizeof(make()) == sizeof(LifetimeTracked)); + assert(sizeof(noisy()) == sizeof(int)); + decltype(noisy()) n = 3; + assert(n == 3); + assert(noisy_calls == 0); + assert(LifetimeTracked::ctorCount == 0); + assert(noisy() == 1); + assert(noisy_calls == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp b/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp new file mode 100644 index 0000000000..18412bf900 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp @@ -0,0 +1,19 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/9: a destructor is odr-used if it is potentially +// invoked. A new-expression for a single object does not potentially invoke it, +// and the object is never deleted, so ~HasUndefinedDestructor is never defined. +#include + +static int t_ctors; + +struct HasUndefinedDestructor { + HasUndefinedDestructor() { ++t_ctors; } + ~HasUndefinedDestructor(); +}; + +int main() { + HasUndefinedDestructor *p = new HasUndefinedDestructor; + assert(p != nullptr); + assert(t_ctors == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp b/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp new file mode 100644 index 0000000000..b3e20b21bd --- /dev/null +++ b/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp @@ -0,0 +1,25 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/9: an assignment operator is odr-used by an +// implicitly-defined assignment operator of another class. +// HasMemberWithUndefinedCopyAssignment is never assigned, so its assignment +// operator is never implicitly defined and +// HasUndefinedCopyAssignment::operator= is never defined. +#include + +static int m_ctors; + +struct HasUndefinedCopyAssignment { + HasUndefinedCopyAssignment() { ++m_ctors; } + HasUndefinedCopyAssignment &operator=(const HasUndefinedCopyAssignment &); +}; + +struct HasMemberWithUndefinedCopyAssignment { + HasUndefinedCopyAssignment m; +}; + +int main() { + HasMemberWithUndefinedCopyAssignment a; + HasMemberWithUndefinedCopyAssignment b; + assert(m_ctors == 2); + return 0; +} diff --git a/tests/std/support/lifetime-tracked.h b/tests/std/support/lifetime-tracked.h new file mode 100644 index 0000000000..62a34ddce5 --- /dev/null +++ b/tests/std/support/lifetime-tracked.h @@ -0,0 +1,34 @@ +#pragma once + +#include + +struct LifetimeTracked { + static inline int ctorCount = 0; + static inline int copyCount = 0; + static inline int dtorCount = 0; + static inline int useCount = 0; + + mutable int uses = 0; + + LifetimeTracked() { ++ctorCount; } + LifetimeTracked(const LifetimeTracked &) { ++copyCount; } + ~LifetimeTracked() { ++dtorCount; } + void use() const { + ++uses; + ++useCount; + } +}; + +struct HasConstexprCtor { + static inline int copyCount = 0; + + int m; + + constexpr HasConstexprCtor(int v) : m(v) {} + HasConstexprCtor(const HasConstexprCtor &o) : m(o.m) { ++copyCount; } +}; + +struct AssertsDtorCountAtExit { + int expected; + ~AssertsDtorCountAtExit() { assert(LifetimeTracked::dtorCount == expected); } +}; From 5794e4ae5bad29b16401008a3b01fd1f8f65fcdb Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:31:44 +0000 Subject: [PATCH 02/11] Add std tests --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8760321390..171be6eb4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,7 @@ add_custom_target("check-unit" "${PROJECT_SOURCE_DIR}/tests/lit/lit.py" ${LIT_FLAGS} "${PROJECT_SOURCE_DIR}/tests/unit" + "${PROJECT_SOURCE_DIR}/tests/std" "${PROJECT_SOURCE_DIR}/tests/ub" "${PROJECT_SOURCE_DIR}/tests/multi-file" DEPENDS cpp2rust libcc2rs From 1b5e3bbbba0ec9621cea4230aed99678dc01a634 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:38:41 +0000 Subject: [PATCH 03/11] Update tests --- ...inline-undefined-in-discarded-statement.rs | 27 +++ .../p13-pointer-to-incomplete-class.rs | 41 +++++ .../p4.1-pure-virtual-qualified-call.rs | 48 +++++ .../p4.1-pure-virtual-without-definition.rs | 36 ++++ .../p5.2-address-of-constant-is-odr-use.rs | 27 +++ ...p5.2-constant-in-lambda-without-capture.rs | 24 +++ .../p9-destructor-not-potentially-invoked.rs | 45 +++++ .../refcount/p9-unused-implicit-assignment.rs | 54 ++++++ ...inline-undefined-in-discarded-statement.rs | 27 +++ .../unsafe/p13-pointer-to-incomplete-class.rs | 38 ++++ .../p4.1-pure-virtual-qualified-call.rs | 48 +++++ .../p4.1-pure-virtual-without-definition.rs | 37 ++++ .../p5.2-address-of-constant-is-odr-use.rs | 29 +++ ...p5.2-constant-in-lambda-without-capture.rs | 25 +++ .../p9-destructor-not-potentially-invoked.rs | 40 ++++ .../unsafe/p9-unused-implicit-assignment.rs | 46 +++++ ...inline-function-reads-per-file-constant.rs | 37 ++++ ...inline-function-reads-per-file-constant.rs | 40 ++++ .../out/refcount/p15-function-template.rs | 172 ++++++++++++++++++ .../out/unsafe/p15-function-template.rs | 132 ++++++++++++++ .../out/refcount/p15-inline-function.rs | 161 ++++++++++++++++ .../out/unsafe/p15-inline-function.rs | 126 +++++++++++++ .../out/refcount/p15-inline-variable.rs | 157 ++++++++++++++++ .../out/unsafe/p15-inline-variable.rs | 127 +++++++++++++ .../refcount/p16-lambda-in-inline-function.rs | 167 +++++++++++++++++ .../unsafe/p16-lambda-in-inline-function.rs | 136 ++++++++++++++ 26 files changed, 1847 insertions(+) create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/refcount/p14.5.1-inline-function-reads-per-file-constant.rs create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs create mode 100644 tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs create mode 100644 tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs create mode 100644 tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs diff --git a/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs new file mode 100644 index 0000000000..373901489e --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs @@ -0,0 +1,27 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static g_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_1() { + {} + (*g_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ g_1() }); + assert!((g_calls_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = g_calls_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs b/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs new file mode 100644 index 0000000000..d108faf3fd --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs @@ -0,0 +1,41 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static x1_0: Value> = Rc::new(RefCell::new(Ptr::::null())); +); +thread_local!( + pub static x2_1: Value> = Rc::new(RefCell::new(Ptr::::null())); +); +pub fn identity_2(mut p: Ptr) -> Ptr { + return (p).clone(); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!(({ (*x1_0.with(Value::clone).borrow()).is_null() })); + assert!( + ({ + ({ ({ identity_2((*x2_1.with(Value::clone).borrow()).clone()) }) } == { + (*x1_0.with(Value::clone).borrow()).clone() + }) + }) + ); + let mut pp: Ptr> = (x1_0.with(|v| v.as_pointer())); + assert!((pp.read()).is_null()); + return 0; +} +#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct X; +pub fn __cpp2rust_init_globals() { + let _ = x1_0.with(|_| ()); + let _ = x2_1.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs new file mode 100644 index 0000000000..75c8783930 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs @@ -0,0 +1,48 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static base_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static derived_calls_1: Value = Rc::new(RefCell::new(0_i32)); +); +pub trait HasPureVirtual { + fn f(&mut self); +} +impl HasPureVirtual { + fn f(&mut self); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct OverridesPureVirtual {} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let d: Value = Rc::new(RefCell::new(::default())); + let mut p: PtrDyn = (d.as_pointer()).to_dyn::(|w| w); + ({ (*p.upgrade().deref_mut()).f() }); + assert!((derived_calls_1.with(|rc| *rc.borrow()) == 1)); + assert!((base_calls_0.with(|rc| *rc.borrow()) == 1)); + ({ ((*d.borrow_mut()) as HasPureVirtual).f() }); + assert!((derived_calls_1.with(|rc| *rc.borrow()) == 1)); + assert!((base_calls_0.with(|rc| *rc.borrow()) == 2)); + return 0; +} +impl HasPureVirtual for OverridesPureVirtual { + fn f(&mut self) { + (*derived_calls_1.with(Value::clone).borrow_mut()).prefix_inc(); + ({ self.f() }); + } +} +pub fn __cpp2rust_init_globals() { + let _ = base_calls_0.with(|_| ()); + let _ = derived_calls_1.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs new file mode 100644 index 0000000000..914bf176fd --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs @@ -0,0 +1,36 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static derived_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +pub trait HasPureVirtual { + fn f(&mut self); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct OverridesPureVirtual {} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let d: Value = Rc::new(RefCell::new(::default())); + let mut p: PtrDyn = (d.as_pointer()).to_dyn::(|w| w); + ({ (*p.upgrade().deref_mut()).f() }); + assert!((derived_calls_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +impl HasPureVirtual for OverridesPureVirtual { + fn f(&mut self) { + (*derived_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = derived_calls_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs new file mode 100644 index 0000000000..c51b5e41b9 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs @@ -0,0 +1,27 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let n: Value = Rc::new(RefCell::new(5)); + let f: Value Ptr>> = Rc::new(RefCell::new(lambda!( + { + let n: Value = Rc::new(RefCell::new((*n.borrow()))); + }, + || -> Ptr { + return (n.as_pointer()); + } + ))); + assert!(({ (({ (*f.borrow()).call() }) != (n.as_pointer())) })); + assert!(({ ((({ (*f.borrow()).call() }).read()) == 5) })); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs new file mode 100644 index 0000000000..ba671e22c8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs @@ -0,0 +1,24 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut n: i32 = 5; + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return 5; + } + }))); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs new file mode 100644 index 0000000000..d87ee90eb3 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs @@ -0,0 +1,45 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static t_ctors_0: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct HasUndefinedDestructor {} +impl HasUndefinedDestructor { + pub fn new() -> Self { + let __this: HasUndefinedDestructor = Self {}; + (*t_ctors_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for HasUndefinedDestructor { + fn default() -> Self { + { HasUndefinedDestructor::new() } + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut p: Ptr = Ptr::alloc(HasUndefinedDestructor::new()); + assert!(!((p).is_null())); + assert!((t_ctors_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub trait HasUndefinedDestructorImpl { + fn destructor(&self) { + unimplemented!() + } +} +impl HasUndefinedDestructorImpl for Ptr {} +pub fn __cpp2rust_init_globals() { + let _ = t_ctors_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs new file mode 100644 index 0000000000..452c6a79b8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs @@ -0,0 +1,54 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static m_ctors_0: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct HasUndefinedCopyAssignment {} +impl HasUndefinedCopyAssignment { + pub fn new() -> Self { + let __this: HasUndefinedCopyAssignment = Self {}; + (*m_ctors_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for HasUndefinedCopyAssignment { + fn default() -> Self { + { HasUndefinedCopyAssignment::new() } + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct HasMemberWithUndefinedCopyAssignment { + #[offset(0)] + #[byte_size(1)] + pub m: HasUndefinedCopyAssignment, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut a: HasMemberWithUndefinedCopyAssignment = + ::default(); + let mut b: HasMemberWithUndefinedCopyAssignment = + ::default(); + assert!((m_ctors_0.with(|rc| *rc.borrow()) == 2)); + return 0; +} +pub trait HasUndefinedCopyAssignmentImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + unimplemented!() + } +} +impl HasUndefinedCopyAssignmentImpl for Ptr {} +pub fn __cpp2rust_init_globals() { + let _ = m_ctors_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs new file mode 100644 index 0000000000..5d9f1975a2 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs @@ -0,0 +1,27 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut g_calls_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_1() { + {} + (*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_0)).prefix_inc(); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { g_1() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const g_calls_0); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs b/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs new file mode 100644 index 0000000000..a544e0f184 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs @@ -0,0 +1,38 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut x1_0: std::cell::LazyCell<*mut X> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); +pub static mut x2_1: std::cell::LazyCell<*mut X> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); +pub unsafe fn identity_2(mut p: *mut X) -> *mut X { + return p; +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0)).is_null()); + assert!( + ((unsafe { identity_2((*std::cell::LazyCell::force_mut(&mut *&raw mut x2_1)),) }) + == (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0))) + ); + let mut pp: *mut *mut X = + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0)) as *mut *mut X); + assert!((*pp).is_null()); + return 0; +} +#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +pub struct X; +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const x1_0); + std::cell::LazyCell::force(&*&raw const x2_1); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs new file mode 100644 index 0000000000..a6989bf591 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs @@ -0,0 +1,48 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut base_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut derived_calls_1: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe trait HasPureVirtual { + unsafe fn f(&mut self); +} +impl HasPureVirtual { + unsafe fn f(&mut self); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct OverridesPureVirtual {} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut d: OverridesPureVirtual = ::default(); + let mut p: *mut dyn HasPureVirtual = (&mut d as *mut OverridesPureVirtual); + (unsafe { (*p).f() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_calls_0)) == (1))); + (unsafe { (d as HasPureVirtual).f() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_calls_0)) == (2))); + return 0; +} +unsafe impl HasPureVirtual for OverridesPureVirtual { + unsafe fn f(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)).prefix_inc(); + (unsafe { self.f() }); + } +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const base_calls_0); + std::cell::LazyCell::force(&*&raw const derived_calls_1); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs new file mode 100644 index 0000000000..ca7ced08fd --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs @@ -0,0 +1,37 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut derived_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe trait HasPureVirtual { + unsafe fn f(&mut self); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct OverridesPureVirtual {} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut d: OverridesPureVirtual = ::default(); + let mut p: *mut dyn HasPureVirtual = (&mut d as *mut OverridesPureVirtual); + (unsafe { (*p).f() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_0)) == (1))); + return 0; +} +unsafe impl HasPureVirtual for OverridesPureVirtual { + unsafe fn f(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_0)).prefix_inc(); + } +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const derived_calls_0); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs new file mode 100644 index 0000000000..da8f8cb966 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs @@ -0,0 +1,29 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let n: i32 = 5; + let mut f: FnPtr *const i32> = lambda_unsafe!( + { + let n: i32 = n; + }, + || -> *const i32 { + return (&n as *const i32); + } + ); + assert!(((unsafe { f.call() }) != (&n as *const i32))); + assert!(((*(unsafe { f.call() })) == (5))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs new file mode 100644 index 0000000000..97326917b0 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs @@ -0,0 +1,25 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let n: i32 = 5; + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return 5; + } + }); + assert!(((unsafe { f.call() }) == (5))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs new file mode 100644 index 0000000000..7d1fd8bd23 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs @@ -0,0 +1,40 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut t_ctors_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct HasUndefinedDestructor {} +impl HasUndefinedDestructor { + pub unsafe fn new() -> Self { + let mut this = Self {}; + (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_0)).prefix_inc(); + this + } +} +impl Default for HasUndefinedDestructor { + fn default() -> Self { + unsafe { HasUndefinedDestructor::new() } + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut p: *mut HasUndefinedDestructor = + (Box::leak(Box::new(HasUndefinedDestructor::new())) as *mut HasUndefinedDestructor); + assert!(!((p).is_null())); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const t_ctors_0); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs new file mode 100644 index 0000000000..b879f8f9e0 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs @@ -0,0 +1,46 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut m_ctors_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct HasUndefinedCopyAssignment {} +impl HasUndefinedCopyAssignment { + pub unsafe fn new() -> Self { + let mut this = Self {}; + (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_0)).prefix_inc(); + this + } +} +impl Default for HasUndefinedCopyAssignment { + fn default() -> Self { + unsafe { HasUndefinedCopyAssignment::new() } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct HasMemberWithUndefinedCopyAssignment { + pub m: HasUndefinedCopyAssignment, +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut a: HasMemberWithUndefinedCopyAssignment = + ::default(); + let mut b: HasMemberWithUndefinedCopyAssignment = + ::default(); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_0)) == (2))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const m_ctors_0); +} diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/refcount/p14.5.1-inline-function-reads-per-file-constant.rs b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/refcount/p14.5.1-inline-function-reads-per-file-constant.rs new file mode 100644 index 0000000000..4d0260cbf4 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/refcount/p14.5.1-inline-function-reads-per-file-constant.rs @@ -0,0 +1,37 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static factor_0: Value = Rc::new(RefCell::new(3)); +); +pub fn scaled_1(mut v: i32) -> i32 { + return (v * factor_0.with(|rc| *rc.borrow())); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!(((factor_0.with(|v| v.as_pointer())) != ({ b_factor_address_2() }))); + assert!(((FnPtr:: i32>::new(scaled_1)) == ({ b_scaled_address_3() }))); + assert!((({ scaled_1(2,) }) == 6)); + assert!((({ b_scaled_4(2,) }) == 6)); + return 0; +} +pub fn b_factor_address_2() -> Ptr { + return (factor_0.with(|v| v.as_pointer())); +} +pub fn b_scaled_address_3() -> FnPtr i32> { + return (FnPtr:: i32>::new(scaled_1)); +} +pub fn b_scaled_4(mut v: i32) -> i32 { + return ({ scaled_1(v) }); +} +pub fn __cpp2rust_init_globals() { + let _ = factor_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs new file mode 100644 index 0000000000..044ff38d0b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs @@ -0,0 +1,40 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut factor_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); +pub unsafe fn scaled_1(mut v: i32) -> i32 { + return ((v) * (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0)) as *const i32) + != (unsafe { b_factor_address_2() })) + ); + assert!(((Some(scaled_1)) == (unsafe { b_scaled_address_3() }))); + assert!(((unsafe { scaled_1(2,) }) == (6))); + assert!(((unsafe { b_scaled_4(2,) }) == (6))); + return 0; +} +pub unsafe fn b_factor_address_2() -> *const i32 { + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0)) as *const i32); +} +pub unsafe fn b_scaled_address_3() -> Option i32> { + return (Some(scaled_1)); +} +pub unsafe fn b_scaled_4(mut v: i32) -> i32 { + return (unsafe { scaled_1(v) }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const factor_0); +} diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs new file mode 100644 index 0000000000..ab0f1c9828 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -0,0 +1,172 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn count_5() -> i32 { + return (*n_7.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn count_8() -> i32 { + return (*n_10.with(Value::clone).borrow_mut()).prefix_inc(); +} +thread_local!( + static t_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + static n_7: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + static t_9: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + static n_10: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static check_11: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((({ count_5() }) == 1)); + assert!((({ b_count_int_12() }) == 2)); + assert!((({ count_5() }) == 3)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((({ count_8() }) == 1)); + assert!((({ b_count_long_13() }) == 2)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + return 0; +} +pub fn b_count_int_12() -> i32 { + return ({ count_5() }); +} +pub fn b_count_long_13() -> i32 { + return ({ count_8() }); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_11.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs new file mode 100644 index 0000000000..ed711f3ee7 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -0,0 +1,132 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub unsafe fn count_5() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_7)).prefix_inc(); +} +pub unsafe fn count_8() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_10)).prefix_inc(); +} +static mut t_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +static mut n_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut t_9: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +static mut n_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut check_11: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + assert!(((unsafe { count_5() }) == (1))); + assert!(((unsafe { b_count_int_12() }) == (2))); + assert!(((unsafe { count_5() }) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((unsafe { count_8() }) == (1))); + assert!(((unsafe { b_count_long_13() }) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + return 0; +} +pub unsafe fn b_count_int_12() -> i32 { + return (unsafe { count_5() }); +} +pub unsafe fn b_count_long_13() -> i32 { + return (unsafe { count_8() }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_11); +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs new file mode 100644 index 0000000000..056d097c5f --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -0,0 +1,161 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn instance_5() -> Ptr { + return t_6.with(|v| v.as_pointer()); +} +thread_local!( + static t_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + pub static check_7: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + ({ LifetimeTrackedImpl::use_(&({ instance_5() })) }); + ({ b_use_8() }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); + assert!((({ instance_5() }).with(|__s| __s.uses) == 2)); + assert!((({ instance_5() }) == ({ b_address_9() }))); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub fn b_use_8() { + ({ LifetimeTrackedImpl::use_(&({ instance_5() })) }); +} +pub fn b_address_9() -> Ptr { + return ({ instance_5() }); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_7.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs new file mode 100644 index 0000000000..d8dc48c58d --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -0,0 +1,126 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub unsafe fn instance_5() -> *mut LifetimeTracked { + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut t_6)); +} +static mut t_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub static mut check_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_5() }))) }); + (unsafe { b_use_8() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); + assert!((((*(unsafe { instance_5() })).uses) == (2))); + assert!(((unsafe { instance_5() }) == (unsafe { b_address_9() }))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + return 0; +} +pub unsafe fn b_use_8() { + (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_5() }))) }); +} +pub unsafe fn b_address_9() -> *mut LifetimeTracked { + return (unsafe { instance_5() }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_7); +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs new file mode 100644 index 0000000000..58b59e2711 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -0,0 +1,157 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static check_5: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); +); +thread_local!( + pub static shared_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); + ({ b_use_7() }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); + assert!(({ ({ (*shared_6.with(Value::clone).borrow()).uses } == 2) })); + assert!(((shared_6.with(|v| v.as_pointer())) == ({ b_address_8() }))); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub fn b_use_7() { + ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); +} +pub fn b_address_8() -> Ptr { + return (shared_6.with(|v| v.as_pointer())); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_5.with(|_| ()); + let _ = shared_6.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs new file mode 100644 index 0000000000..f499e645dc --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -0,0 +1,127 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut check_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); +pub static mut shared_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); + (unsafe { b_use_7() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)).uses) == (2))); + assert!( + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + as *mut LifetimeTracked) + == (unsafe { b_address_8() })) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + return 0; +} +pub unsafe fn b_use_7() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); +} +pub unsafe fn b_address_8() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + as *mut LifetimeTracked); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_5); + std::cell::LazyCell::force(&*&raw const shared_6); +} diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs new file mode 100644 index 0000000000..1b0626969d --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -0,0 +1,167 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn f_5(mut cond: bool, mut p: FnPtr) { + if cond { + ({ + f_5( + false, + FnPtr::::new(|| { + ({ LifetimeTrackedImpl::use_(&local_6.with(|v| v.as_pointer())) }); + }), + ) + }); + } else { + ({ p.call() }); + } +} +thread_local!( + static local_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + pub static check_7: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + ({ f_5(true, FnPtr::::null()) }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); + ({ b_call_8() }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); + return 0; +} +pub fn b_call_8() { + ({ f_5(true, FnPtr::::null()) }); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_7.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs new file mode 100644 index 0000000000..783e872355 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -0,0 +1,136 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub unsafe fn f_5(mut cond: bool, mut p: Option) { + if cond { + (unsafe { + f_5( + false, + Some(|| unsafe { + (unsafe { + LifetimeTracked::use_( + &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_6)), + ) + }); + }), + ) + }); + } else { + (unsafe { (p).unwrap()() }); + } +} +static mut local_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub static mut check_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + (unsafe { f_5(true, None) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); + (unsafe { b_call_8() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); + return 0; +} +pub unsafe fn b_call_8() { + (unsafe { f_5(true, None) }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_7); +} From e91dbf3742a3ad6c2e838e92edf3b028adc8f98e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:41:49 +0000 Subject: [PATCH 04/11] Update tests --- .../out/refcount/p11-discarded-statement.rs | 148 +++++++++++++ .../out/refcount/p3.3-member-access.rs | 145 +++++++++++++ .../out/refcount/p3.7-conditional.rs | 155 ++++++++++++++ .../basic.def.odr/out/refcount/p3.8-comma.rs | 157 ++++++++++++++ .../p5.1-constant-reference-in-lambda.rs | 148 +++++++++++++ .../refcount/p5.2-class-object-is-odr-used.rs | 150 ++++++++++++++ .../p5.3-discarded-value-in-lambda.rs | 150 ++++++++++++++ .../p6-evaluated-binding-is-captured.rs | 191 +++++++++++++++++ ...p6-unevaluated-binding-needs-no-capture.rs | 182 ++++++++++++++++ .../p7-member-access-captures-this.rs | 196 ++++++++++++++++++ .../p7-unevaluated-this-needs-no-capture.rs | 174 ++++++++++++++++ ...p8-unevaluated-call-needs-no-definition.rs | 151 ++++++++++++++ .../out/unsafe/p11-discarded-statement.rs | 115 ++++++++++ .../out/unsafe/p3.2-subscript.rs | 112 ++++++++++ .../out/unsafe/p3.3-member-access.rs | 112 ++++++++++ .../out/unsafe/p3.7-conditional.rs | 119 +++++++++++ .../basic.def.odr/out/unsafe/p3.8-comma.rs | 120 +++++++++++ .../p5.1-constant-reference-in-lambda.rs | 117 +++++++++++ .../unsafe/p5.2-class-object-is-odr-used.rs | 116 +++++++++++ .../unsafe/p5.3-discarded-value-in-lambda.rs | 116 +++++++++++ .../p6-evaluated-binding-is-captured.rs | 150 ++++++++++++++ ...p6-unevaluated-binding-needs-no-capture.rs | 143 +++++++++++++ .../unsafe/p7-member-access-captures-this.rs | 158 ++++++++++++++ .../p7-unevaluated-this-needs-no-capture.rs | 138 ++++++++++++ ...p8-unevaluated-call-needs-no-definition.rs | 120 +++++++++++ .../CMakeLists.txt | 5 - .../a.cpp | 11 - .../b.cpp | 5 - .../p14-unnamed-enumeration-in-two-files/h.h | 10 - 29 files changed, 3583 insertions(+), 31 deletions(-) create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs delete mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt delete mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp delete mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp delete mode 100644 tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs new file mode 100644 index 0000000000..b42e27f7fa --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs @@ -0,0 +1,148 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_6() { + { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ g_6() }); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = else_runs_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs new file mode 100644 index 0000000000..b9693b9adb --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs @@ -0,0 +1,145 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return HasConstexprCtor::new({ 5 }).m; + } + }))); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs new file mode 100644 index 0000000000..67ac26c7f8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs @@ -0,0 +1,155 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); + let mut k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( + |mut b: bool| -> i32 { + { + return { + (if b { + HasConstexprCtor::new({ 7 }) + } else { + HasConstexprCtor::new({ 9 }) + }) + .m + }; + } + }, + ))); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call(true,) }) == 7) })); + assert!(({ (({ (*f.borrow()).call(false,) }) == 9) })); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs new file mode 100644 index 0000000000..48197387b0 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs @@ -0,0 +1,157 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static left_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return { + { + (*left_5.with(Value::clone).borrow_mut()).prefix_inc(); + HasConstexprCtor::new({ 5 }) + } + .m + }; + } + }))); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((left_5.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((left_5.with(|rc| *rc.borrow()) == 1)); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = left_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs new file mode 100644 index 0000000000..7fd997ca52 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs @@ -0,0 +1,148 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static global_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let r: Ptr = global_5.with(|v| v.as_pointer()); + let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { + ({ LifetimeTrackedImpl::use_(&global_5.with(|v| v.as_pointer())) }); + }))); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + ({ (*f.borrow()).call() }); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!(({ ({ (*global_5.with(Value::clone).borrow()).uses } == 1) })); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = global_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs new file mode 100644 index 0000000000..83fba89b2a --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs @@ -0,0 +1,150 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let f: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::copy_from({ + k.as_pointer() + }))); + }, + || -> i32 { + let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ k.as_pointer() }); + return c.m; + } + ))); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 1)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 2)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs new file mode 100644 index 0000000000..8f6aa1e0df --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs @@ -0,0 +1,150 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); + let f: Value> = Rc::new(RefCell::new(lambda!( + { + let t: Value = + Rc::new(RefCell::new(LifetimeTracked::copy_from({ t.as_pointer() }))); + }, + || {} + ))); + let _dtor_f = + std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + ({ (*f.borrow()).call() }); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs b/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs new file mode 100644 index 0000000000..5bb4361fc1 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs @@ -0,0 +1,191 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[byte_size(8)] +pub struct HasTwoMembers { + #[offset(0)] + #[byte_size(4)] + pub a: LifetimeTracked, + #[offset(4)] + #[byte_size(4)] + pub b: LifetimeTracked, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let p: Value = Rc::new(RefCell::new(HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + })); + let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + let __decomp_5: Ptr = p.as_pointer(); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + let f: Value> = Rc::new(RefCell::new(lambda!( + { + let a: Value = Rc::new(RefCell::new(LifetimeTracked::copy_from({ + field_ptr!(__decomp_5, a) + }))); + }, + || { + ({ LifetimeTrackedImpl::use_(&field_ptr!(__decomp_5, a)) }); + } + ))); + let _dtor_f = + std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); + ({ (*f.borrow()).call() }); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); + assert!(({ ({ (*p.borrow()).a.uses } == 0) })); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait HasTwoMembersImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; + fn destructor(&self); +} +impl HasTwoMembersImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, a); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), _arg0) + }); + ({ + let _arg0: Ptr = field_ptr!(_a0, b); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), _arg0) + }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, b).destructor(); + field_ptr!(self, a).destructor(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs new file mode 100644 index 0000000000..5dce8a59cf --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs @@ -0,0 +1,182 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[byte_size(8)] +pub struct HasTwoMembers { + #[offset(0)] + #[byte_size(4)] + pub a: LifetimeTracked, + #[offset(4)] + #[byte_size(4)] + pub b: LifetimeTracked, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let p: Value = Rc::new(RefCell::new(HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + })); + let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); + let __decomp_5: Ptr = p.as_pointer(); + let f: Value usize>> = + Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }))); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait HasTwoMembersImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; + fn destructor(&self); +} +impl HasTwoMembersImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, a); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), _arg0) + }); + ({ + let _arg0: Ptr = field_ptr!(_a0, b); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), _arg0) + }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, b).destructor(); + field_ptr!(self, a).destructor(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs new file mode 100644 index 0000000000..f6ee27620c --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs @@ -0,0 +1,196 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(8)] +pub struct HasMemberUsedInLambda { + #[offset(0)] + #[byte_size(4)] + pub x: LifetimeTracked, + #[offset(4)] + pub n: i32, +} +impl Default for HasMemberUsedInLambda { + fn default() -> Self { + { + HasMemberUsedInLambda { + x: ::default(), + n: 1, + } + } + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let c: Value = Rc::new(RefCell::new(::default())); + let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let f: Value i32>> = Rc::new(RefCell::new( + ({ HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), + )); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 1) })); + assert!(({ ({ (*c.borrow()).x.uses } == 1) })); + (*c.borrow_mut()).n = 10; + assert!(({ (({ (*f.borrow()).call() }) == 10) })); + assert!(({ ({ (*c.borrow()).x.uses } == 2) })); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait HasMemberUsedInLambdaImpl { + fn makeLambda(&self) -> FnPtr i32>; + fn copy_assign(&self, _a0: Ptr) -> Ptr; + fn destructor(&self); +} +impl HasMemberUsedInLambdaImpl for Ptr { + fn makeLambda(&self) -> FnPtr i32> { + return lambda!( + { + let this_: Value> = + Rc::new(RefCell::new((*self).clone())); + }, + || -> i32 { + ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); + return (*this_.borrow()).with(|__s| __s.n); + } + ); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, x); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) + }); + field!((*self), n).write({ _a0.with(|__s| __s.n) }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, x).destructor(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs new file mode 100644 index 0000000000..cbdb2a7d7d --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs @@ -0,0 +1,174 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[byte_size(4)] +pub struct HasMemberUsedInLambda { + #[offset(0)] + #[byte_size(4)] + pub x: LifetimeTracked, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let c: Value = Rc::new(RefCell::new(::default())); + let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let f: Value usize>> = Rc::new(RefCell::new( + ({ HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) }), + )); + assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait HasMemberUsedInLambdaImpl { + fn sizer(&self) -> FnPtr usize>; + fn copy_assign(&self, _a0: Ptr) -> Ptr; + fn destructor(&self); +} +impl HasMemberUsedInLambdaImpl for Ptr { + fn sizer(&self) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, x); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) + }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, x).destructor(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs new file mode 100644 index 0000000000..a274b0e49b --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs @@ -0,0 +1,151 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static noisy_calls_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn noisy_6() -> i32 { + (*noisy_calls_5.with(Value::clone).borrow_mut()).prefix_inc(); + return 1; +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((4usize == 4usize)); + assert!((::std::mem::size_of::() == ::std::mem::size_of::())); + let mut n: i32 = 3; + assert!((n == 3)); + assert!((noisy_calls_5.with(|rc| *rc.borrow()) == 0)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((({ noisy_6() }) == 1)); + assert!((noisy_calls_5.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = noisy_calls_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs new file mode 100644 index 0000000000..2f39ee3b0c --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs @@ -0,0 +1,115 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut else_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_6() { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { g_6() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const else_runs_5); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs new file mode 100644 index 0000000000..3d52b9bdd7 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs @@ -0,0 +1,112 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let arr: [HasConstexprCtor; 2] = [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize].m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((unsafe { f.call() }) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs new file mode 100644 index 0000000000..09bdbc28d5 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs @@ -0,0 +1,112 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return HasConstexprCtor::new({ 5 }).m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs new file mode 100644 index 0000000000..11eab9f04d --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs @@ -0,0 +1,119 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); + let k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { + unsafe { + return (if b { + HasConstexprCtor::new({ 7 }) + } else { + HasConstexprCtor::new({ 9 }) + }) + .m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((unsafe { f.call(true,) }) == (7))); + assert!(((unsafe { f.call(false,) }) == (9))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs new file mode 100644 index 0000000000..37e0b2f7a3 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs @@ -0,0 +1,120 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut left_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return { + (*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)).prefix_inc(); + HasConstexprCtor::new({ 5 }) + } + .m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)) == (0))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const left_5); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs new file mode 100644 index 0000000000..7a2b2bea66 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs @@ -0,0 +1,117 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut global_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)); + let mut f: FnPtr = FnPtr::::new(|| unsafe { + (unsafe { + LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_5))) + }); + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)).uses) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const global_5); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs new file mode 100644 index 0000000000..7abe4b92d1 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs @@ -0,0 +1,116 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = lambda_unsafe!( + { + let k: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + }, + || -> i32 { + let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + return c.m; + } + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (1))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (2))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs new file mode 100644 index 0000000000..1c13438d11 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs @@ -0,0 +1,116 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut t: LifetimeTracked = LifetimeTracked::new(); + let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); + let mut f: FnPtr = lambda_unsafe!( + { + let t: LifetimeTracked = LifetimeTracked::copy_from({ &t }); + }, + || {} + ); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs b/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs new file mode 100644 index 0000000000..547b680d00 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs @@ -0,0 +1,150 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +pub struct HasTwoMembers { + pub a: LifetimeTracked, + pub b: LifetimeTracked, +} +impl HasTwoMembers { + pub unsafe fn copy_assign(&mut self, _a0: *const HasTwoMembers) -> *mut HasTwoMembers { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).a; + LifetimeTracked::copy_assign(&mut self.a, _arg0) + }); + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).b; + LifetimeTracked::copy_assign(&mut self.b, _arg0) + }); + return &mut (*(self as *mut HasTwoMembers)); + } +} +impl HasTwoMembers { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.b); + LifetimeTracked::destructor(&mut self.a); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut p: HasTwoMembers = HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + }; + let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + let __decomp_5: *mut HasTwoMembers = &mut p; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + let mut f: FnPtr = lambda_unsafe!( + { + let a: LifetimeTracked = LifetimeTracked::copy_from({ &(*__decomp_5).a }); + }, + || { + (unsafe { LifetimeTracked::use_(&(*__decomp_5).a) }); + } + ); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); + assert!(((p.a.uses) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs new file mode 100644 index 0000000000..14c04b39a9 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs @@ -0,0 +1,143 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +pub struct HasTwoMembers { + pub a: LifetimeTracked, + pub b: LifetimeTracked, +} +impl HasTwoMembers { + pub unsafe fn copy_assign(&mut self, _a0: *const HasTwoMembers) -> *mut HasTwoMembers { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).a; + LifetimeTracked::copy_assign(&mut self.a, _arg0) + }); + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).b; + LifetimeTracked::copy_assign(&mut self.b, _arg0) + }); + return &mut (*(self as *mut HasTwoMembers)); + } +} +impl HasTwoMembers { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.b); + LifetimeTracked::destructor(&mut self.a); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut p: HasTwoMembers = HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + }; + let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); + let __decomp_5: *mut HasTwoMembers = &mut p; + let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { + unsafe { + return ::std::mem::size_of::(); + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs new file mode 100644 index 0000000000..57b22454a3 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs @@ -0,0 +1,158 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct HasMemberUsedInLambda { + pub x: LifetimeTracked, + pub n: i32, +} +impl HasMemberUsedInLambda { + pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { + return lambda_unsafe!( + { + let this_: *mut HasMemberUsedInLambda = (self as *mut HasMemberUsedInLambda); + }, + || -> i32 { + (unsafe { LifetimeTracked::use_(&(*this_).x) }); + return (*this_).n; + } + ); + } + pub unsafe fn copy_assign( + &mut self, + _a0: *const HasMemberUsedInLambda, + ) -> *mut HasMemberUsedInLambda { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).x; + LifetimeTracked::copy_assign(&mut self.x, _arg0) + }); + self.n = (*_a0).n; + return &mut (*(self as *mut HasMemberUsedInLambda)); + } +} +impl HasMemberUsedInLambda { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.x); + } +} +impl Default for HasMemberUsedInLambda { + fn default() -> Self { + unsafe { + HasMemberUsedInLambda { + x: ::default(), + n: 1, + } + } + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut c: HasMemberUsedInLambda = ::default(); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let mut f: FnPtr i32> = (unsafe { HasMemberUsedInLambda::makeLambda(&mut c) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!(((unsafe { f.call() }) == (1))); + assert!(((c.x.uses) == (1))); + c.n = 10; + assert!(((unsafe { f.call() }) == (10))); + assert!(((c.x.uses) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs new file mode 100644 index 0000000000..d911ab4bdf --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs @@ -0,0 +1,138 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +pub struct HasMemberUsedInLambda { + pub x: LifetimeTracked, +} +impl HasMemberUsedInLambda { + pub unsafe fn sizer(&mut self) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + unsafe { + return ::std::mem::size_of::(); + } + }); + } + pub unsafe fn copy_assign( + &mut self, + _a0: *const HasMemberUsedInLambda, + ) -> *mut HasMemberUsedInLambda { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).x; + LifetimeTracked::copy_assign(&mut self.x, _arg0) + }); + return &mut (*(self as *mut HasMemberUsedInLambda)); + } +} +impl HasMemberUsedInLambda { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.x); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut c: HasMemberUsedInLambda = ::default(); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let mut f: FnPtr usize> = (unsafe { HasMemberUsedInLambda::sizer(&mut c) }); + assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs new file mode 100644 index 0000000000..9ad94a260c --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs @@ -0,0 +1,120 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut noisy_calls_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn noisy_6() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)).prefix_inc(); + return 1; +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((::std::mem::size_of::()) == (::std::mem::size_of::())) + ); + assert!(((::std::mem::size_of::()) == (::std::mem::size_of::()))); + let mut n: i32 = 3; + assert!(((n) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + assert!(((unsafe { noisy_6() }) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const noisy_calls_5); +} diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt deleted file mode 100644 index 684947285c..0000000000 --- a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.20) -project(p14_unnamed_enumeration_in_two_files LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp deleted file mode 100644 index 8c69b82cd4..0000000000 --- a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/a.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "h.h" -#include - -int main() { - current = A; - assert(current == 1); - b_set_b(); - assert(current == B); - assert(current == 2); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp deleted file mode 100644 index ddbaf5a11b..0000000000 --- a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/b.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "h.h" - -decltype(A) current; - -void b_set_b() { current = B; } diff --git a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h b/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h deleted file mode 100644 index 610ca56f9e..0000000000 --- a/tests/std/basic/basic.def.odr/p14-unnamed-enumeration-in-two-files/h.h +++ /dev/null @@ -1,10 +0,0 @@ -// N4950 [basic.def.odr]/14: an unnamed enumeration may be defined in several -// translation units if every definition satisfies the requirements; the -// definitions then denote one type, so `current` is one object of that type. -#pragma once - -enum { A = 1, B }; - -extern decltype(A) current; - -void b_set_b(); From 6aca3a2bc3e813ff55c296d6fe85c74e0548fb7f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:42:06 +0000 Subject: [PATCH 05/11] Include parent in cxxflags --- tests/lit/lit/formats/Cpp2RustTest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 809b33b23a..079e01482e 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -485,6 +485,7 @@ def cpp2rust_command(cc_input, build_dir, model, rs_file, extra_cxxflags): model, "-o", str(rs_file), + f"-cxxflags=-I{cc_input.parent}", ] for flag in extra_cxxflags: cmd.append(f"-cxxflags={flag}") From a6aea1e9c2edaaa1d91665f639296eb0c1d33979 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:54:29 +0000 Subject: [PATCH 06/11] Exclude test not accepted by Clang --- tests/lit/lit/formats/Cpp2RustTest.py | 2 ++ tests/std/basic/basic.def.odr/lit.local.cfg | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 tests/std/basic/basic.def.odr/lit.local.cfg diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 079e01482e..3b7cb10d1d 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -373,6 +373,8 @@ def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig): yield lit.Test.Test(testSuite, path_in_suite, localConfig) return for entry in source_path.iterdir(): + if entry.name in localConfig.excludes: + continue if entry.is_file() and entry.suffix in (".cpp", ".c"): yield lit.Test.Test( testSuite, path_in_suite + (entry.name,), localConfig diff --git a/tests/std/basic/basic.def.odr/lit.local.cfg b/tests/std/basic/basic.def.odr/lit.local.cfg new file mode 100644 index 0000000000..95d17633b6 --- /dev/null +++ b/tests/std/basic/basic.def.odr/lit.local.cfg @@ -0,0 +1,4 @@ +# Clang treats a discarded-value use as an odr-use, so [=] captures the variable +# and the C++ program itself fails its asserts. Clang implements CWG2083 only +# partially: https://github.com/llvm/llvm-project/issues/127086 +config.excludes = list(config.excludes) + ["p5.3-discarded-value-in-lambda.cpp"] From 8e4453e122cff8d6a86dc16522bc0081fa00e23e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 11:58:21 +0000 Subject: [PATCH 07/11] Update test expectations for cpp2rust limitations --- .../test.expectations | 5 +++++ .../basic.def.odr/p15-function-template/test.expectations | 3 +++ tests/std/basic/basic.def.odr/p3.2-subscript.cpp | 3 +++ .../basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp | 3 +++ .../basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp | 3 +++ 5 files changed, 17 insertions(+) create mode 100644 tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/test.expectations create mode 100644 tests/std/basic/basic.def.odr/p15-function-template/test.expectations diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/test.expectations b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/test.expectations new file mode 100644 index 0000000000..b147980970 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/test.expectations @@ -0,0 +1,5 @@ +// panic: refcount +// no-compile: unsafe +// The converter emits one object for a constant that has internal linkage in +// each file, and in the unsafe model compares a function with a function +// pointer of a different type. diff --git a/tests/std/basic/basic.def.odr/p15-function-template/test.expectations b/tests/std/basic/basic.def.odr/p15-function-template/test.expectations new file mode 100644 index 0000000000..36b34de9d4 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-function-template/test.expectations @@ -0,0 +1,3 @@ +// panic: refcount, unsafe +// The converter initializes a static local lazily, so one that is never used +// is never constructed. diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp index 528f51eb49..413c351397 100644 --- a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp +++ b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp @@ -1,3 +1,6 @@ +// translation-fail: refcount +// The refcount converter asserts on a constant array that a lambda uses +// without capturing it. // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation // with an array operand are those of the operand. Reading arr[1].m does not diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp index a9f5366f52..fd9c9b823c 100644 --- a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp +++ b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp @@ -1,3 +1,6 @@ +// no-compile: refcount, unsafe +// The converter drops the body of a pure virtual function and the +// qualification of calls to it. // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/4.1: a pure virtual function is named by an // id-expression with an explicitly qualified name. HasPureVirtual::f is pure diff --git a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp index 73c3b3ad5b..a95ab833ab 100644 --- a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp +++ b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp @@ -1,3 +1,6 @@ +// no-compile: refcount, unsafe +// Inside the lambda the converter refers to the original structured binding, +// not to the captured copy. // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/6: a structured binding is odr-used if it appears as a // potentially-evaluated expression, so [=] captures a by copy. From 1bb90f8b5a44af4151962ed6982b230c2d03865f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 12:13:10 +0000 Subject: [PATCH 08/11] Update tests --- tests/std/basic/basic.def.odr/lit.local.cfg | 4 +- .../p11-discarded-statement-in-template.rs | 154 +++++++++++++++ ...defined-variable-in-discarded-statement.rs | 148 +++++++++++++++ .../p5.1-local-reference-is-odr-used.rs | 154 +++++++++++++++ .../p5.2-mutable-subobject-is-odr-used.rs | 79 ++++++++ ...p8-unevaluated-call-needs-no-definition.rs | 2 + .../refcount/p9-unused-copy-constructor.rs | 45 +++++ .../p11-discarded-statement-in-template.rs | 121 ++++++++++++ ...defined-variable-in-discarded-statement.rs | 115 ++++++++++++ .../p5.1-local-reference-is-odr-used.rs | 120 ++++++++++++ .../p5.2-mutable-subobject-is-odr-used.rs | 67 +++++++ ...p8-unevaluated-call-needs-no-definition.rs | 2 + .../out/unsafe/p9-unused-copy-constructor.rs | 45 +++++ .../p11-discarded-statement-in-template.cpp | 28 +++ ...efined-variable-in-discarded-statement.cpp | 26 +++ .../p14-class-in-two-files/CMakeLists.txt | 5 + .../p14-class-in-two-files/a.cpp | 15 ++ .../p14-class-in-two-files/b.cpp | 10 + .../basic.def.odr/p14-class-in-two-files/h.h | 22 +++ .../out/refcount/p14-class-in-two-files.rs | 174 +++++++++++++++++ .../out/unsafe/p14-class-in-two-files.rs | 143 ++++++++++++++ .../CMakeLists.txt | 5 + .../p15-class-template-static-member/a.cpp | 14 ++ .../p15-class-template-static-member/b.cpp | 7 + .../p15-class-template-static-member/h.h | 16 ++ .../p15-class-template-static-member.rs | 166 +++++++++++++++++ .../p15-class-template-static-member.rs | 137 ++++++++++++++ .../CMakeLists.txt | 5 + .../a.cpp | 16 ++ .../b.cpp | 6 + .../p16-default-argument-lambda-in-class/h.h | 21 +++ .../p16-default-argument-lambda-in-class.rs | 175 ++++++++++++++++++ .../p16-default-argument-lambda-in-class.rs | 141 ++++++++++++++ .../p5.1-local-reference-is-odr-used.cpp | 18 ++ .../p5.2-mutable-subobject-is-odr-used.cpp | 26 +++ ...8-unevaluated-call-needs-no-definition.cpp | 2 + .../p9-unused-copy-constructor.cpp | 23 +++ 37 files changed, 2255 insertions(+), 2 deletions(-) create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs create mode 100644 tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs create mode 100644 tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp create mode 100644 tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs create mode 100644 tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/h.h create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs create mode 100644 tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/CMakeLists.txt create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/b.cpp create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/h.h create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs create mode 100644 tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs create mode 100644 tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp create mode 100644 tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp create mode 100644 tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp diff --git a/tests/std/basic/basic.def.odr/lit.local.cfg b/tests/std/basic/basic.def.odr/lit.local.cfg index 95d17633b6..e2ce84f021 100644 --- a/tests/std/basic/basic.def.odr/lit.local.cfg +++ b/tests/std/basic/basic.def.odr/lit.local.cfg @@ -1,4 +1,4 @@ # Clang treats a discarded-value use as an odr-use, so [=] captures the variable -# and the C++ program itself fails its asserts. Clang implements CWG2083 only -# partially: https://github.com/llvm/llvm-project/issues/127086 +# and the C++ program itself fails its asserts: +# https://github.com/llvm/llvm-project/issues/127086 config.excludes = list(config.excludes) + ["p5.3-discarded-value-in-lambda.cpp"] diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs new file mode 100644 index 0000000000..13df6ead31 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs @@ -0,0 +1,154 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_6(mut _a0: i32) { + { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn g_7(mut _a0: i8) { + { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ g_6(1) }); + ({ g_7(('c' as i8)) }); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 2)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = else_runs_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs new file mode 100644 index 0000000000..be9718f8f7 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs @@ -0,0 +1,148 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_7() { + { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ g_7() }); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = else_runs_5.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs new file mode 100644 index 0000000000..51bd47a168 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs @@ -0,0 +1,154 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); + let r: Ptr = t.as_pointer(); + let f: Value> = Rc::new(RefCell::new(lambda!( + { + let r: Value = + Rc::new(RefCell::new(LifetimeTracked::copy_from({ (r).clone() }))); + }, + || { + ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); + } + ))); + let _dtor_f = + std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); + ({ (*f.borrow()).call() }); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); + assert!(({ ({ (*t.borrow()).uses } == 0) })); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs new file mode 100644 index 0000000000..90658d3548 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs @@ -0,0 +1,79 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static copies_0: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(8)] +pub struct HasMutableMember { + #[offset(0)] + pub value: i32, + #[offset(4)] + pub scratch: i32, +} +impl HasMutableMember { + pub fn new(mut v: i32) -> Self { + Self { + value: v, + scratch: 0, + } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasMutableMember = Self { + value: o.with(|__s| __s.value), + scratch: o.with(|__s| __s.scratch), + }; + (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasMutableMember { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(HasMutableMember { + value: self.value.clone(), + scratch: self.scratch.clone(), + })); + HasMutableMember::copy_from(__src.as_pointer()) + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let k: Value = Rc::new(RefCell::new(HasMutableMember::new({ 5 }))); + let f: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let k: Value = Rc::new(RefCell::new(HasMutableMember::copy_from({ + k.as_pointer() + }))); + }, + || -> i32 { + return { (*k.borrow()).value }; + } + ))); + assert!((copies_0.with(|rc| *rc.borrow()) == 1)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copies_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub trait HasMutableMemberImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasMutableMemberImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), value).write({ _a0.with(|__s| __s.value) }); + field!((*self), scratch).write({ _a0.with(|__s| __s.scratch) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = copies_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs index a274b0e49b..b6edf46762 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs @@ -98,6 +98,8 @@ pub fn main() { fn main_0() -> i32 { assert!((4usize == 4usize)); assert!((::std::mem::size_of::() == ::std::mem::size_of::())); + assert!(!(false)); + assert!(!(false)); let mut n: i32 = 3; assert!((n == 3)); assert!((noisy_calls_5.with(|rc| *rc.borrow()) == 0)); diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs new file mode 100644 index 0000000000..a06f95b486 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs @@ -0,0 +1,45 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctor_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Record, ByteRepr, FnPtrArg)] +#[byte_size(4)] +pub struct HasUndefinedCopyCtor { + #[offset(0)] + pub value: i32, +} +impl HasUndefinedCopyCtor { + pub fn new() -> Self { + let __this: HasUndefinedCopyCtor = Self { value: 3 }; + (*ctor_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for HasUndefinedCopyCtor { + fn default() -> Self { + { HasUndefinedCopyCtor::new() } + } +} +pub fn read_1(object: Ptr) -> i32 { + return object.with(|__s| __s.value); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let a: Value = Rc::new(RefCell::new(HasUndefinedCopyCtor::new())); + assert!((({ read_1(a.as_pointer(),) }) == 3)); + assert!((ctor_calls_0.with(|rc| *rc.borrow()) == 1)); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = ctor_calls_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs new file mode 100644 index 0000000000..e4fed882d4 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs @@ -0,0 +1,121 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut else_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_6(mut _a0: i32) { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + } +} +pub unsafe fn g_7(mut _a0: libc::c_char) { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { g_6(1) }); + (unsafe { g_7(('c' as libc::c_char)) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const else_runs_5); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs new file mode 100644 index 0000000000..7dff9b6b7d --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs @@ -0,0 +1,115 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut else_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_7() { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { g_7() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const else_runs_5); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs new file mode 100644 index 0000000000..291746392d --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs @@ -0,0 +1,120 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut t: LifetimeTracked = LifetimeTracked::new(); + let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); + let r: *mut LifetimeTracked = &mut t; + let mut f: FnPtr = lambda_unsafe!( + { + let r: LifetimeTracked = LifetimeTracked::copy_from({ r }); + }, + || { + (unsafe { LifetimeTracked::use_(&r) }); + } + ); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); + assert!(((t.uses) == (0))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs new file mode 100644 index 0000000000..7144f6258c --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs @@ -0,0 +1,67 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasMutableMember { + pub value: i32, + pub scratch: i32, +} +impl HasMutableMember { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { + value: v, + scratch: 0, + }; + this + } + pub unsafe fn copy_from(o: *const HasMutableMember) -> Self { + let mut this = Self { + value: (*o).value, + scratch: (*o).scratch, + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasMutableMember) -> *mut HasMutableMember { + self.value = (*_a0).value; + self.scratch = (*_a0).scratch; + return &mut (*(self as *mut HasMutableMember)); + } +} +impl Clone for HasMutableMember { + fn clone(&self) -> Self { + unsafe { HasMutableMember::copy_from(self as *const HasMutableMember) } + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let k: HasMutableMember = HasMutableMember::new({ 5 }); + let mut f: FnPtr i32> = lambda_unsafe!( + { + let k: HasMutableMember = HasMutableMember::copy_from({ &k }); + }, + || -> i32 { + return k.value; + } + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const copies_0); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs index 9ad94a260c..82edea7222 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs @@ -102,6 +102,8 @@ unsafe fn main_0() -> i32 { ((::std::mem::size_of::()) == (::std::mem::size_of::())) ); assert!(((::std::mem::size_of::()) == (::std::mem::size_of::()))); + assert!(!(false)); + assert!(!(false)); let mut n: i32 = 3; assert!(((n) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)) == (0))); diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs new file mode 100644 index 0000000000..26571439b9 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs @@ -0,0 +1,45 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctor_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(FnPtrArg)] +pub struct HasUndefinedCopyCtor { + pub value: i32, +} +impl HasUndefinedCopyCtor { + pub unsafe fn new() -> Self { + let mut this = Self { value: 3 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_0)).prefix_inc(); + this + } +} +impl Default for HasUndefinedCopyCtor { + fn default() -> Self { + unsafe { HasUndefinedCopyCtor::new() } + } +} +pub unsafe fn read_1(object: *const HasUndefinedCopyCtor) -> i32 { + return (*object).value; +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut a: HasUndefinedCopyCtor = HasUndefinedCopyCtor::new(); + assert!(((unsafe { read_1(&a,) }) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_0)) == (1))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctor_calls_0); +} diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp new file mode 100644 index 0000000000..0761a57b3d --- /dev/null +++ b/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp @@ -0,0 +1,28 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/11: a definition is required only for functions +// odr-used outside of a discarded statement. In a template the discarded +// branch is not instantiated; undefined() is called only there, so it is never +// defined and never runs. +#include "../../support/lifetime-tracked.h" +#include + +static int else_runs; + +LifetimeTracked undefined(); + +template void g(T) { + if constexpr (sizeof(T) > 1000) { + undefined().use(); + } else { + ++else_runs; + } +} + +int main() { + g(1); + g('c'); + assert(else_runs == 2); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp new file mode 100644 index 0000000000..51094b65e1 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp @@ -0,0 +1,26 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/11: a definition is required only for variables +// odr-used outside of a discarded statement. undefined is used only in a +// discarded statement, so it is never defined. +#include "../../support/lifetime-tracked.h" +#include + +static int else_runs; + +extern LifetimeTracked undefined; + +void g() { + if constexpr (false) { + undefined.use(); + } else { + ++else_runs; + } +} + +int main() { + g(); + assert(else_runs == 1); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/CMakeLists.txt b/tests/std/basic/basic.def.odr/p14-class-in-two-files/CMakeLists.txt new file mode 100644 index 0000000000..c204d3f2ab --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p14_class_in_two_files LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp b/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp new file mode 100644 index 0000000000..1317fb0887 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp @@ -0,0 +1,15 @@ +#include "h.h" +#include + +int main() { + HasInlineMembers::shared.use(); + HasInlineMembers::instance().use(); + b_use(); + assert(LifetimeTracked::ctorCount == 2); + assert(HasInlineMembers::shared.uses == 2); + assert(HasInlineMembers::instance().uses == 2); + assert(&HasInlineMembers::shared == b_shared_address()); + assert(&HasInlineMembers::instance() == b_instance_address()); + assert(LifetimeTracked::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/b.cpp b/tests/std/basic/basic.def.odr/p14-class-in-two-files/b.cpp new file mode 100644 index 0000000000..bf04b66e58 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/b.cpp @@ -0,0 +1,10 @@ +#include "h.h" + +void b_use() { + HasInlineMembers::shared.use(); + HasInlineMembers::instance().use(); +} + +LifetimeTracked *b_shared_address() { return &HasInlineMembers::shared; } + +LifetimeTracked *b_instance_address() { return &HasInlineMembers::instance(); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h b/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h new file mode 100644 index 0000000000..b1e10f34eb --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h @@ -0,0 +1,22 @@ +// N4950 [basic.def.odr]/14 and /15: a class may be defined in several +// translation units. A member function defined in the class and an inline +// static data member are then single entities: one static local variable and +// one object, each constructed once and destroyed once. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +inline AssertsDtorCountAtExit check{2}; + +struct HasInlineMembers { + static inline LifetimeTracked shared; + + static LifetimeTracked &instance() { + static LifetimeTracked local; + return local; + } +}; + +void b_use(); +LifetimeTracked *b_shared_address(); +LifetimeTracked *b_instance_address(); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs new file mode 100644 index 0000000000..466d5668ea --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -0,0 +1,174 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static check_5: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); +); +thread_local!( + pub static shared_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct HasInlineMembers {} +impl HasInlineMembers { + pub fn instance() -> Ptr { + return local_7.with(|v| v.as_pointer()); + } +} +thread_local!( + static local_7: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ b_use_8() }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + assert!(({ ({ (*shared_6.with(Value::clone).borrow()).uses } == 2) })); + assert!((({ HasInlineMembers::instance() }).with(|__s| __s.uses) == 2)); + assert!(((shared_6.with(|v| v.as_pointer())) == ({ b_shared_address_9() }))); + assert!((({ HasInlineMembers::instance() }) == ({ b_instance_address_10() }))); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub fn b_use_8() { + ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); +} +pub fn b_shared_address_9() -> Ptr { + return (shared_6.with(|v| v.as_pointer())); +} +pub fn b_instance_address_10() -> Ptr { + return ({ HasInlineMembers::instance() }); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_5.with(|_| ()); + let _ = shared_6.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs new file mode 100644 index 0000000000..d4f32d0bbc --- /dev/null +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -0,0 +1,143 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut check_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } }); +pub static mut shared_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct HasInlineMembers {} +impl HasInlineMembers { + pub unsafe fn instance() -> *mut LifetimeTracked { + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut local_7)); + } +} +static mut local_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); + (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { b_use_8() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)).uses) == (2))); + assert!((((*(unsafe { HasInlineMembers::instance() })).uses) == (2))); + assert!( + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + as *mut LifetimeTracked) + == (unsafe { b_shared_address_9() })) + ); + assert!(((unsafe { HasInlineMembers::instance() }) == (unsafe { b_instance_address_10() }))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + return 0; +} +pub unsafe fn b_use_8() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); + (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); +} +pub unsafe fn b_shared_address_9() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + as *mut LifetimeTracked); +} +pub unsafe fn b_instance_address_10() -> *mut LifetimeTracked { + return (unsafe { HasInlineMembers::instance() }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_5); + std::cell::LazyCell::force(&*&raw const shared_6); +} diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/CMakeLists.txt b/tests/std/basic/basic.def.odr/p15-class-template-static-member/CMakeLists.txt new file mode 100644 index 0000000000..1d28aeea84 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p15_class_template_static_member LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp b/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp new file mode 100644 index 0000000000..d6bdd6cdc8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp @@ -0,0 +1,14 @@ +#include "h.h" +#include + +int main() { + HasStaticMember::member.use(); + b_use_int(); + b_use_long(); + assert(HasStaticMember::member.uses == 2); + assert(HasStaticMember::member.uses == 1); + assert(&HasStaticMember::member == b_int_address()); + assert(LifetimeTracked::ctorCount == 2); + assert(LifetimeTracked::copyCount == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/b.cpp b/tests/std/basic/basic.def.odr/p15-class-template-static-member/b.cpp new file mode 100644 index 0000000000..65fe7d2a9f --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/b.cpp @@ -0,0 +1,7 @@ +#include "h.h" + +void b_use_int() { HasStaticMember::member.use(); } + +void b_use_long() { HasStaticMember::member.use(); } + +LifetimeTracked *b_int_address() { return &HasStaticMember::member; } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/h.h b/tests/std/basic/basic.def.odr/p15-class-template-static-member/h.h new file mode 100644 index 0000000000..6860be6688 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/h.h @@ -0,0 +1,16 @@ +// N4950 [basic.def.odr]/15: a static data member of a class template may be +// defined in several translation units and behaves as a single entity: one +// object per specialization. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +template struct HasStaticMember { + static LifetimeTracked member; +}; + +template LifetimeTracked HasStaticMember::member; + +void b_use_int(); +void b_use_long(); +LifetimeTracked *b_int_address(); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs new file mode 100644 index 0000000000..a2ad002fd8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -0,0 +1,166 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +thread_local!( + pub static member_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct HasStaticMember_int_ {} +thread_local!( + pub static member_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct HasStaticMember_long_ {} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); + ({ b_use_int_7() }); + ({ b_use_long_8() }); + assert!(({ ({ (*member_5.with(Value::clone).borrow()).uses } == 2) })); + assert!(({ ({ (*member_6.with(Value::clone).borrow()).uses } == 1) })); + assert!(((member_5.with(|v| v.as_pointer())) == ({ b_int_address_9() }))); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub fn b_use_int_7() { + ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); +} +pub fn b_use_long_8() { + ({ LifetimeTrackedImpl::use_(&member_6.with(|v| v.as_pointer())) }); +} +pub fn b_int_address_9() -> Ptr { + return (member_5.with(|v| v.as_pointer())); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = member_5.with(|_| ()); + let _ = member_6.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs new file mode 100644 index 0000000000..e6669be086 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -0,0 +1,137 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +pub static mut member_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct HasStaticMember_int_ {} +pub static mut member_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct HasStaticMember_long_ {} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); + (unsafe { b_use_int_7() }); + (unsafe { b_use_long_8() }); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)).uses) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_6)).uses) == (1))); + assert!( + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)) + as *mut LifetimeTracked) + == (unsafe { b_int_address_9() })) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); + return 0; +} +pub unsafe fn b_use_int_7() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); +} +pub unsafe fn b_use_long_8() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_6))) }); +} +pub unsafe fn b_int_address_9() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)) + as *mut LifetimeTracked); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const member_5); + std::cell::LazyCell::force(&*&raw const member_6); +} diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/CMakeLists.txt b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/CMakeLists.txt new file mode 100644 index 0000000000..474c5df409 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(p16_default_argument_lambda_in_class LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp new file mode 100644 index 0000000000..de6f4d262c --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp @@ -0,0 +1,16 @@ +#include "h.h" +#include + +AssertsDtorCountAtExit check{1}; + +int main() { + assert(LifetimeTracked::ctorCount == 0); + X x; + x.h(true); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 1); + b_call(); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::useCount == 2); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/b.cpp b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/b.cpp new file mode 100644 index 0000000000..5adfe787e8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/b.cpp @@ -0,0 +1,6 @@ +#include "h.h" + +void b_call() { + X x; + x.h(true); +} diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/h.h b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/h.h new file mode 100644 index 0000000000..85fdf40fd5 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/h.h @@ -0,0 +1,21 @@ +// N4950 [basic.def.odr]/16, Example 6: X is a class whose member function h +// has a lambda-expression in a default argument. Defined in several +// translation units, the lambda denotes the same closure type in each, so it +// has one static local variable. +#pragma once + +#include "../../../support/lifetime-tracked.h" + +struct X { + void h(bool cond, void (*p)() = [] { + static LifetimeTracked local; + local.use(); + }) { + if (cond) + h(false); + else + p(); + } +}; + +void b_call(); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs new file mode 100644 index 0000000000..3a7ccf1428 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -0,0 +1,175 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct X {} +thread_local!( + static local_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + pub static check_6: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); + let x: Value = Rc::new(RefCell::new(::default())); + ({ XImpl::h(&x.as_pointer(), true, None) }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); + ({ b_call_7() }); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); + return 0; +} +pub fn b_call_7() { + let x: Value = Rc::new(RefCell::new(::default())); + ({ XImpl::h(&x.as_pointer(), true, None) }); +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub trait XImpl { + fn h(&self, cond: bool, p: Option>); +} +impl XImpl for Ptr { + fn h(&self, mut cond: bool, p: Option>) { + let mut p: FnPtr = p.unwrap_or_else(|| { + FnPtr::::new(|| { + ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); + }) + }); + if cond { + ({ XImpl::h(self, false, None) }); + } else { + ({ p.call() }); + } + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); + let _ = check_6.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs new file mode 100644 index 0000000000..7011ff695b --- /dev/null +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -0,0 +1,141 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct AssertsDtorCountAtExit { + pub expected: i32, +} +impl AssertsDtorCountAtExit { + pub unsafe fn destructor(&mut self) { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct X {} +impl X { + pub unsafe fn h(&mut self, mut cond: bool, mut p: Option>) { + let mut p: Option = p.unwrap_or_else(|| unsafe { + Some(|| unsafe { + (unsafe { + LifetimeTracked::use_( + &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), + ) + }); + }) + }); + if cond { + (unsafe { X::h(self, false, None) }); + } else { + (unsafe { (p).unwrap()() }); + } + } +} +static mut local_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub static mut check_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); + let mut x: X = ::default(); + (unsafe { X::h(&mut x, true, None) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); + (unsafe { b_call_7() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); + return 0; +} +pub unsafe fn b_call_7() { + let mut x: X = ::default(); + (unsafe { X::h(&mut x, true, None) }); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const check_6); +} diff --git a/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp new file mode 100644 index 0000000000..1de3cfe2b5 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp @@ -0,0 +1,18 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.1: only a reference that is usable in constant +// expressions is exempt. r refers to a local object, so it is odr-used and [=] +// captures it, which copies the object it refers to. +#include "../../support/lifetime-tracked.h" +#include + +int main() { + LifetimeTracked t; + LifetimeTracked &r = t; + auto f = [=] { r.use(); }; + assert(LifetimeTracked::copyCount == 1); + f(); + assert(LifetimeTracked::copyCount == 1); + assert(LifetimeTracked::useCount == 1); + assert(t.uses == 0); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp new file mode 100644 index 0000000000..83be4b8102 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp @@ -0,0 +1,26 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/5.2: the exemption requires a variable with no mutable +// subobjects. k has one, so reading k.value odr-uses k and [=] captures it. +#include + +static int copies; + +struct HasMutableMember { + int value; + mutable int scratch; + + constexpr HasMutableMember(int v) : value(v), scratch(0) {} + HasMutableMember(const HasMutableMember &o) + : value(o.value), scratch(o.scratch) { + ++copies; + } +}; + +int main() { + constexpr HasMutableMember k{5}; + auto f = [=] { return k.value; }; + assert(copies == 1); + assert(f() == 5); + assert(copies == 1); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp index 14e51137e3..8a63c642da 100644 --- a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp +++ b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp @@ -18,6 +18,8 @@ int noisy() { int main() { assert(sizeof(make()) == sizeof(LifetimeTracked)); assert(sizeof(noisy()) == sizeof(int)); + assert(!noexcept(make())); + assert(!noexcept(noisy())); decltype(noisy()) n = 3; assert(n == 3); assert(noisy_calls == 0); diff --git a/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp b/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp new file mode 100644 index 0000000000..28b95ee6e2 --- /dev/null +++ b/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp @@ -0,0 +1,23 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.def.odr]/9: a constructor is odr-used only where an +// initialization selects it. No HasUndefinedCopyCtor is ever copied, so its +// copy constructor is never defined. +#include + +static int ctor_calls; + +struct HasUndefinedCopyCtor { + int value = 3; + + HasUndefinedCopyCtor() { ++ctor_calls; } + HasUndefinedCopyCtor(const HasUndefinedCopyCtor &); +}; + +int read(const HasUndefinedCopyCtor &object) { return object.value; } + +int main() { + HasUndefinedCopyCtor a; + assert(read(a) == 3); + assert(ctor_calls == 1); + return 0; +} From f6ec2d46cf2d874af72cd0ec1aa5aea3c58f96f6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 12:42:02 +0000 Subject: [PATCH 09/11] format --- .../basic.def.odr/p11-discarded-statement-in-template.cpp | 3 ++- tests/std/basic/basic.def.odr/p11-discarded-statement.cpp | 3 ++- .../p11-undefined-variable-in-discarded-statement.cpp | 3 ++- tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp | 3 ++- .../p14.5.1-inline-function-reads-per-file-constant/a.cpp | 3 ++- .../basic/basic.def.odr/p15-class-template-static-member/a.cpp | 3 ++- tests/std/basic/basic.def.odr/p15-function-template/a.cpp | 3 ++- tests/std/basic/basic.def.odr/p15-inline-function/a.cpp | 3 ++- tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp | 3 ++- .../basic.def.odr/p16-default-argument-lambda-in-class/a.cpp | 3 ++- .../basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp | 3 ++- tests/std/basic/basic.def.odr/p3.2-subscript.cpp | 3 ++- tests/std/basic/basic.def.odr/p3.3-member-access.cpp | 3 ++- tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp | 3 ++- tests/std/basic/basic.def.odr/p3.7-conditional.cpp | 3 ++- tests/std/basic/basic.def.odr/p3.8-comma.cpp | 3 ++- .../basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp | 3 ++- .../basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp | 3 ++- .../std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp | 3 ++- .../std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp | 3 ++- .../basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp | 3 ++- .../basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp | 3 ++- .../std/basic/basic.def.odr/p7-member-access-captures-this.cpp | 3 ++- .../basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp | 3 ++- .../basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp | 3 ++- 25 files changed, 50 insertions(+), 25 deletions(-) diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp index 0761a57b3d..2109b89302 100644 --- a/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp +++ b/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp @@ -3,9 +3,10 @@ // odr-used outside of a discarded statement. In a template the discarded // branch is not instantiated; undefined() is called only there, so it is never // defined and never runs. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + static int else_runs; LifetimeTracked undefined(); diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp index 2a3978690a..7b558b4429 100644 --- a/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp +++ b/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/11: a definition is required only for functions // odr-used outside of a discarded statement. undefined() is called only in a // discarded statement, so it is never defined and never runs. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + static int else_runs; LifetimeTracked undefined(); diff --git a/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp index 51094b65e1..129d2582c5 100644 --- a/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp +++ b/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/11: a definition is required only for variables // odr-used outside of a discarded statement. undefined is used only in a // discarded statement, so it is never defined. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + static int else_runs; extern LifetimeTracked undefined; diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp b/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp index 1317fb0887..17f3ad662f 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + int main() { HasInlineMembers::shared.use(); HasInlineMembers::instance().use(); diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp index 93c701864a..099798ab92 100644 --- a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp +++ b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + int main() { assert(&factor != b_factor_address()); assert(&scaled == b_scaled_address()); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp b/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp index d6bdd6cdc8..787d3e845b 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + int main() { HasStaticMember::member.use(); b_use_int(); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp index 056b489401..ed36ad1e2c 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + AssertsDtorCountAtExit check{2}; int main() { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp index 9e4bd67adf..00b3f9c39e 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + AssertsDtorCountAtExit check{1}; int main() { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp b/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp index 4a0ec83010..ffb84d86fc 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + int main() { shared.use(); b_use(); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp index de6f4d262c..d0f3160421 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + AssertsDtorCountAtExit check{1}; int main() { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp index 309d261209..2688be6e7d 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp @@ -1,6 +1,7 @@ -#include "h.h" #include +#include "h.h" + AssertsDtorCountAtExit check{1}; int main() { diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp index 413c351397..acd8074770 100644 --- a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp +++ b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp @@ -5,9 +5,10 @@ // N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation // with an array operand are those of the operand. Reading arr[1].m does not // odr-use arr, so [=] does not capture it. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { constexpr HasConstexprCtor arr[2] = {3, 4}; auto f = [=] { return arr[1].m; }; diff --git a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp index ee900024d5..52d9abccb6 100644 --- a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp +++ b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/3.3: the potential results of E1.E2 naming a non-static // data member are those of E1. Reading k.m does not odr-use k, so [=] does not // capture it. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { constexpr HasConstexprCtor k{5}; auto f = [=] { return k.m; }; diff --git a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp index dd9c716935..b8224780aa 100644 --- a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp +++ b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp @@ -2,9 +2,10 @@ // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/3.5: the potential results of E1.*E2 are those of E1. // Reading k.*pm does not odr-use k, so [=] does not capture it. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { constexpr HasConstexprCtor k{5}; constexpr int HasConstexprCtor::*pm = &HasConstexprCtor::m; diff --git a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp index ae24ffc484..04bec2ef9c 100644 --- a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp +++ b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/3.7: the potential results of a glvalue conditional // expression are those of its second and third operands. Neither k1 nor k2 is // odr-used, so [=] captures neither. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { constexpr HasConstexprCtor k1{7}; constexpr HasConstexprCtor k2{9}; diff --git a/tests/std/basic/basic.def.odr/p3.8-comma.cpp b/tests/std/basic/basic.def.odr/p3.8-comma.cpp index 905cac761c..ea9b5ba035 100644 --- a/tests/std/basic/basic.def.odr/p3.8-comma.cpp +++ b/tests/std/basic/basic.def.odr/p3.8-comma.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/3.8: the potential results of a comma expression are // those of its right operand. k is not odr-used, so [=] does not capture it; // the left operand is still evaluated. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + static int left; int main() { diff --git a/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp b/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp index 2887ef8082..20f84999bd 100644 --- a/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp +++ b/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/5.1: a reference that is usable in constant expressions // is not odr-used. [=] therefore does not capture r, and the lambda uses the // object r refers to. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + LifetimeTracked global; int main() { diff --git a/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp index 1de3cfe2b5..59ecfc0d83 100644 --- a/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp +++ b/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/5.1: only a reference that is usable in constant // expressions is exempt. r refers to a local object, so it is odr-used and [=] // captures it, which copies the object it refers to. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { LifetimeTracked t; LifetimeTracked &r = t; diff --git a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp index a9489e0466..da02052280 100644 --- a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp +++ b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp @@ -1,9 +1,10 @@ // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/5.2: the exemption covers only expressions of non-class // type. Copying the constant k as a whole odr-uses it, so [=] captures it. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { constexpr HasConstexprCtor k{5}; auto f = [=] { diff --git a/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp b/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp index 16dde2f168..d0755e7112 100644 --- a/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp +++ b/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/5.3: a variable named by a discarded-value expression // to which the lvalue-to-rvalue conversion is not applied is not odr-used, so // [=] does not capture t. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + int main() { LifetimeTracked t; auto f = [=] { (void)t; }; diff --git a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp index a95ab833ab..a1e0db0181 100644 --- a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp +++ b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp @@ -4,9 +4,10 @@ // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/6: a structured binding is odr-used if it appears as a // potentially-evaluated expression, so [=] captures a by copy. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + struct HasTwoMembers { LifetimeTracked a; LifetimeTracked b; diff --git a/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp index 96f438dacd..b8598ea901 100644 --- a/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp +++ b/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/6: a structured binding is odr-used only if it appears // as a potentially-evaluated expression. In sizeof it is unevaluated, so [=] // does not capture a. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + struct HasTwoMembers { LifetimeTracked a; LifetimeTracked b; diff --git a/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp b/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp index 04bd3be32b..a3482fe9d0 100644 --- a/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp +++ b/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp @@ -3,9 +3,10 @@ // potentially-evaluated expression, including through the implicit // transformation of a member name. [=] captures this, not the member x, and the // lambda sees later changes to the object. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + struct HasMemberUsedInLambda { LifetimeTracked x; int n = 1; diff --git a/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp index 3528d4bcbc..74a80bc9a7 100644 --- a/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp +++ b/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp @@ -2,9 +2,10 @@ // N4950 [basic.def.odr]/7: *this is odr-used only if this appears as a // potentially-evaluated expression. In sizeof the member name is unevaluated, // so the lambda needs no capture. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + struct HasMemberUsedInLambda { LifetimeTracked x; auto sizer() { diff --git a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp index 8a63c642da..fb7fb7c2f5 100644 --- a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp +++ b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp @@ -3,9 +3,10 @@ // potentially-evaluated expression. make() is named only in unevaluated // operands, so it is never defined; noisy() is defined, but an unevaluated call // does not run it. -#include "../../support/lifetime-tracked.h" #include +#include "../../support/lifetime-tracked.h" + static int noisy_calls; LifetimeTracked make(); From 85ca25b4edda7db5b24177e57b8d53abf8073bf7 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 12:55:35 +0000 Subject: [PATCH 10/11] Fix ODR use of p3.2 --- cpp2rust/converter/converter_lib.cpp | 3 +- .../out/refcount/p3.2-subscript.rs | 147 ++++++++++++++++++ .../basic/basic.def.odr/p3.2-subscript.cpp | 3 - 3 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index a819bfb022..083fa6ba96 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1507,7 +1507,8 @@ static const clang::FieldDecl * AsLambdaCaptureField(const clang::FunctionDecl *fn, const clang::Expr *expr) { auto call = AsLambdaOperatorCall(fn); auto ref = clang::dyn_cast(expr); - if (!call || !ref || !ref->refersToEnclosingVariableOrCapture()) { + if (!call || !ref || !ref->refersToEnclosingVariableOrCapture() || + ref->isNonOdrUse() != clang::NOUR_None) { return nullptr; } llvm::DenseMap fields; diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs new file mode 100644 index 0000000000..5012389cf8 --- /dev/null +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs @@ -0,0 +1,147 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static copyCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct AssertsDtorCountAtExit { + #[offset(0)] + pub expected: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut arr: [HasConstexprCtor; 2] = + [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize] + .m; + } + }))); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 4) })); + assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + return 0; +} +pub trait AssertsDtorCountAtExitImpl { + fn destructor(&self); +} +impl AssertsDtorCountAtExitImpl for Ptr { + fn destructor(&self) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = copyCount_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp index acd8074770..d27672aa1c 100644 --- a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp +++ b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp @@ -1,6 +1,3 @@ -// translation-fail: refcount -// The refcount converter asserts on a constant array that a lambda uses -// without capturing it. // ADDITIONAL_COMPILE_FLAGS: -std=c++23 // N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation // with an array operand are those of the operand. Reading arr[1].m does not From d593910ed617c566c6188603ba059d9c3c07d790 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 15 Nov 2026 13:06:35 +0000 Subject: [PATCH 11/11] Reduce bloat of all included helper structs --- .../p11-discarded-statement-in-template.rs | 71 ++----------- .../out/refcount/p11-discarded-statement.rs | 65 ++---------- ...defined-variable-in-discarded-statement.rs | 65 ++---------- .../out/refcount/p3.2-subscript.rs | 89 +---------------- .../out/refcount/p3.3-member-access.rs | 89 +---------------- .../out/refcount/p3.7-conditional.rs | 89 +---------------- .../basic.def.odr/out/refcount/p3.8-comma.rs | 99 ++----------------- .../p5.1-constant-reference-in-lambda.rs | 63 +----------- .../p5.1-local-reference-is-odr-used.rs | 53 ---------- .../refcount/p5.2-class-object-is-odr-used.rs | 89 +---------------- ...p6-unevaluated-binding-needs-no-capture.rs | 55 +---------- .../p7-member-access-captures-this.rs | 53 ---------- .../p7-unevaluated-this-needs-no-capture.rs | 53 ---------- ...p8-unevaluated-call-needs-no-definition.rs | 67 ++----------- .../p11-discarded-statement-in-template.rs | 56 ++--------- .../out/unsafe/p11-discarded-statement.rs | 50 ++-------- ...defined-variable-in-discarded-statement.rs | 50 ++-------- .../out/unsafe/p3.2-subscript.rs | 66 +------------ .../out/unsafe/p3.3-member-access.rs | 66 +------------ .../out/unsafe/p3.7-conditional.rs | 66 +------------ .../basic.def.odr/out/unsafe/p3.8-comma.rs | 76 ++------------ .../p5.1-constant-reference-in-lambda.rs | 48 +-------- .../p5.1-local-reference-is-odr-used.rs | 38 ------- .../unsafe/p5.2-class-object-is-odr-used.rs | 66 +------------ ...p6-unevaluated-binding-needs-no-capture.rs | 40 +------- .../unsafe/p7-member-access-captures-this.rs | 38 ------- .../p7-unevaluated-this-needs-no-capture.rs | 38 ------- ...p8-unevaluated-call-needs-no-definition.rs | 52 ++-------- .../basic.def.odr/p14-class-in-two-files/h.h | 1 + .../out/refcount/p14-class-in-two-files.rs | 71 +++---------- .../out/unsafe/p14-class-in-two-files.rs | 62 ++++-------- .../p15-class-template-static-member.rs | 83 +++------------- .../p15-class-template-static-member.rs | 70 +++---------- .../basic.def.odr/p15-function-template/a.cpp | 1 + .../out/refcount/p15-function-template.rs | 77 ++++----------- .../out/unsafe/p15-function-template.rs | 66 ++++--------- .../basic.def.odr/p15-inline-function/a.cpp | 1 + .../out/refcount/p15-inline-function.rs | 65 +++--------- .../out/unsafe/p15-inline-function.rs | 54 +++------- .../basic.def.odr/p15-inline-variable/h.h | 1 + .../out/refcount/p15-inline-variable.rs | 63 +++--------- .../out/unsafe/p15-inline-variable.rs | 54 +++------- .../a.cpp | 1 + .../p16-default-argument-lambda-in-class.rs | 51 ++-------- .../p16-default-argument-lambda-in-class.rs | 40 ++------ .../p16-lambda-in-inline-function/a.cpp | 1 + .../refcount/p16-lambda-in-inline-function.rs | 59 ++--------- .../unsafe/p16-lambda-in-inline-function.rs | 48 ++------- .../basic/basic.def.odr/p3.2-subscript.cpp | 2 +- .../basic.def.odr/p3.3-member-access.cpp | 2 +- .../basic.def.odr/p3.5-pointer-to-member.cpp | 2 +- .../basic/basic.def.odr/p3.7-conditional.cpp | 2 +- tests/std/basic/basic.def.odr/p3.8-comma.cpp | 2 +- .../p5.2-class-object-is-odr-used.cpp | 2 +- .../std/support/asserts-dtor-count-at-exit.h | 9 ++ tests/std/support/has-constexpr-ctor.h | 10 ++ tests/std/support/lifetime-tracked.h | 16 --- 57 files changed, 344 insertions(+), 2322 deletions(-) create mode 100644 tests/std/support/asserts-dtor-count-at-exit.h create mode 100644 tests/std/support/has-constexpr-ctor.h diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs index 13df6ead31..e7a86fa471 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs @@ -50,51 +50,16 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_6(mut _a0: i32) { +pub fn g_5(mut _a0: i32) { { - (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } } -pub fn g_7(mut _a0: i8) { +pub fn g_6(mut _a0: i8) { { - (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } } pub fn main() { @@ -102,30 +67,13 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - ({ g_6(1) }); - ({ g_7(('c' as i8)) }); - assert!((else_runs_5.with(|rc| *rc.borrow()) == 2)); + ({ g_5(1) }); + ({ g_6(('c' as i8)) }); + assert!((else_runs_4.with(|rc| *rc.borrow()) == 2)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -149,6 +97,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = else_runs_5.with(|_| ()); + let _ = else_runs_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs index b42e27f7fa..fa6426b662 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs @@ -50,46 +50,11 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_6() { +pub fn g_5() { { - (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } } pub fn main() { @@ -97,29 +62,12 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - ({ g_6() }); - assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + ({ g_5() }); + assert!((else_runs_4.with(|rc| *rc.borrow()) == 1)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -143,6 +91,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = else_runs_5.with(|_| ()); + let _ = else_runs_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs index be9718f8f7..6f83bb084a 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs @@ -50,46 +50,11 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_7() { +pub fn g_6() { { - (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } } pub fn main() { @@ -97,29 +62,12 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - ({ g_7() }); - assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + ({ g_6() }); + assert!((else_runs_4.with(|rc| *rc.borrow()) == 1)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -143,6 +91,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = else_runs_5.with(|_| ()); + let _ = else_runs_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs index 5012389cf8..e19b445e6c 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs @@ -7,50 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] @@ -67,7 +24,7 @@ impl HasConstexprCtor { let __this: HasConstexprCtor = Self { m: o.with(|__s| __s.m), }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); __this } } @@ -78,12 +35,6 @@ impl Clone for HasConstexprCtor { HasConstexprCtor::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -98,19 +49,11 @@ fn main_0() -> i32 { .m; } }))); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 4) })); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait HasConstexprCtorImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; } @@ -120,28 +63,6 @@ impl HasConstexprCtorImpl for Ptr { return (*self).clone(); } } -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); + let _ = copyCount_0.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs index b9693b9adb..efd144bcc1 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs @@ -7,50 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] @@ -67,7 +24,7 @@ impl HasConstexprCtor { let __this: HasConstexprCtor = Self { m: o.with(|__s| __s.m), }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); __this } } @@ -78,12 +35,6 @@ impl Clone for HasConstexprCtor { HasConstexprCtor::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -96,19 +47,11 @@ fn main_0() -> i32 { return HasConstexprCtor::new({ 5 }).m; } }))); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait HasConstexprCtorImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; } @@ -118,28 +61,6 @@ impl HasConstexprCtorImpl for Ptr { return (*self).clone(); } } -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); + let _ = copyCount_0.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs index 67ac26c7f8..25e7fb46c0 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs @@ -7,50 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] @@ -67,7 +24,7 @@ impl HasConstexprCtor { let __this: HasConstexprCtor = Self { m: o.with(|__s| __s.m), }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); __this } } @@ -78,12 +35,6 @@ impl Clone for HasConstexprCtor { HasConstexprCtor::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -105,20 +56,12 @@ fn main_0() -> i32 { } }, ))); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call(true,) }) == 7) })); assert!(({ (({ (*f.borrow()).call(false,) }) == 9) })); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait HasConstexprCtorImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; } @@ -128,28 +71,6 @@ impl HasConstexprCtorImpl for Ptr { return (*self).clone(); } } -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); + let _ = copyCount_0.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs index 48197387b0..5b56355563 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs @@ -7,50 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] @@ -67,7 +24,7 @@ impl HasConstexprCtor { let __this: HasConstexprCtor = Self { m: o.with(|__s| __s.m), }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); __this } } @@ -78,14 +35,8 @@ impl Clone for HasConstexprCtor { HasConstexprCtor::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} thread_local!( - pub static left_5: Value = Rc::new(RefCell::new(0_i32)); + pub static left_1: Value = Rc::new(RefCell::new(0_i32)); ); pub fn main() { __cpp2rust_init_globals(); @@ -98,28 +49,20 @@ fn main_0() -> i32 { { return { { - (*left_5.with(Value::clone).borrow_mut()).prefix_inc(); + (*left_1.with(Value::clone).borrow_mut()).prefix_inc(); HasConstexprCtor::new({ 5 }) } .m }; } }))); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); - assert!((left_5.with(|rc| *rc.borrow()) == 0)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((left_1.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((left_5.with(|rc| *rc.borrow()) == 1)); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 0)); + assert!((left_1.with(|rc| *rc.borrow()) == 1)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait HasConstexprCtorImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; } @@ -129,29 +72,7 @@ impl HasConstexprCtorImpl for Ptr { return (*self).clone(); } } -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = left_5.with(|_| ()); + let _ = copyCount_0.with(|_| ()); + let _ = left_1.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs index 7fd997ca52..3978f86f02 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs @@ -50,76 +50,24 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static global_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + pub static global_4: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); } fn main_0() -> i32 { - let r: Ptr = global_5.with(|v| v.as_pointer()); + let r: Ptr = global_4.with(|v| v.as_pointer()); let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&global_5.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&global_4.with(|v| v.as_pointer())) }); }))); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); ({ (*f.borrow()).call() }); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!(({ ({ (*global_5.with(Value::clone).borrow()).uses } == 1) })); + assert!(({ ({ (*global_4.with(Value::clone).borrow()).uses } == 1) })); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -143,6 +91,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = global_5.with(|_| ()); + let _ = global_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs index 51bd47a168..ccb9caa3d5 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs @@ -49,41 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -110,23 +75,6 @@ fn main_0() -> i32 { assert!(({ ({ (*t.borrow()).uses } == 0) })); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -150,5 +98,4 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs index 83fba89b2a..3ce8d8efea 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs @@ -7,50 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] @@ -67,7 +24,7 @@ impl HasConstexprCtor { let __this: HasConstexprCtor = Self { m: o.with(|__s| __s.m), }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); __this } } @@ -78,12 +35,6 @@ impl Clone for HasConstexprCtor { HasConstexprCtor::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -101,19 +52,11 @@ fn main_0() -> i32 { return c.m; } ))); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 1)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 1)); assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((copyCount_4.with(|rc| *rc.borrow()) == 2)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 2)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} pub trait HasConstexprCtorImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; } @@ -123,28 +66,6 @@ impl HasConstexprCtorImpl for Ptr { return (*self).clone(); } } -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); + let _ = copyCount_0.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs index 5dce8a59cf..b7505989f2 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs @@ -49,41 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] #[byte_size(8)] pub struct HasTwoMembers { @@ -104,7 +69,7 @@ fn main_0() -> i32 { b: LifetimeTracked::new(), })); let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); - let __decomp_5: Ptr = p.as_pointer(); + let __decomp_4: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { { @@ -117,23 +82,6 @@ fn main_0() -> i32 { assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait HasTwoMembersImpl { fn copy_assign(&self, _a0: Ptr) -> Ptr; fn destructor(&self); @@ -178,5 +126,4 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs index f6ee27620c..3abce6375c 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs @@ -49,41 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(8)] pub struct HasMemberUsedInLambda { @@ -122,23 +87,6 @@ fn main_0() -> i32 { assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait HasMemberUsedInLambdaImpl { fn makeLambda(&self) -> FnPtr i32>; fn copy_assign(&self, _a0: Ptr) -> Ptr; @@ -192,5 +140,4 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs index cbdb2a7d7d..eafa84bd78 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs @@ -49,41 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] #[byte_size(4)] pub struct HasMemberUsedInLambda { @@ -106,23 +71,6 @@ fn main_0() -> i32 { assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait HasMemberUsedInLambdaImpl { fn sizer(&self) -> FnPtr usize>; fn copy_assign(&self, _a0: Ptr) -> Ptr; @@ -170,5 +118,4 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs index b6edf46762..f605cf5f42 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs +++ b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs @@ -50,45 +50,10 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); + pub static noisy_calls_4: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static noisy_calls_5: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn noisy_6() -> i32 { - (*noisy_calls_5.with(Value::clone).borrow_mut()).prefix_inc(); +pub fn noisy_5() -> i32 { + (*noisy_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); return 1; } pub fn main() { @@ -102,29 +67,12 @@ fn main_0() -> i32 { assert!(!(false)); let mut n: i32 = 3; assert!((n == 3)); - assert!((noisy_calls_5.with(|rc| *rc.borrow()) == 0)); + assert!((noisy_calls_4.with(|rc| *rc.borrow()) == 0)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((({ noisy_6() }) == 1)); - assert!((noisy_calls_5.with(|rc| *rc.borrow()) == 1)); + assert!((({ noisy_5() }) == 1)); + assert!((noisy_calls_4.with(|rc| *rc.borrow()) == 1)); return 0; } -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -148,6 +96,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = noisy_calls_5.with(|_| ()); + let _ = noisy_calls_4.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs index e4fed882d4..cc68b2c9da 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs @@ -48,53 +48,16 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut else_runs_5: std::cell::LazyCell = +pub static mut else_runs_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_6(mut _a0: i32) { +pub unsafe fn g_5(mut _a0: i32) { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); } } -pub unsafe fn g_7(mut _a0: libc::c_char) { +pub unsafe fn g_6(mut _a0: libc::c_char) { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); } } pub fn main() { @@ -104,9 +67,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { g_6(1) }); - (unsafe { g_7(('c' as libc::c_char)) }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (2))); + (unsafe { g_5(1) }); + (unsafe { g_6(('c' as libc::c_char)) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); return 0; @@ -116,6 +79,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const else_runs_5); + std::cell::LazyCell::force(&*&raw const else_runs_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs index 2f39ee3b0c..62195d121e 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs @@ -48,48 +48,11 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut else_runs_5: std::cell::LazyCell = +pub static mut else_runs_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_6() { +pub unsafe fn g_5() { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); } } pub fn main() { @@ -99,8 +62,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { g_6() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + (unsafe { g_5() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); return 0; @@ -110,6 +73,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const else_runs_5); + std::cell::LazyCell::force(&*&raw const else_runs_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs index 7dff9b6b7d..c3919f0863 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs @@ -48,48 +48,11 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut else_runs_5: std::cell::LazyCell = +pub static mut else_runs_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_7() { +pub unsafe fn g_6() { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); } } pub fn main() { @@ -99,8 +62,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { g_7() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + (unsafe { g_6() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); return 0; @@ -110,6 +73,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const else_runs_5); + std::cell::LazyCell::force(&*&raw const else_runs_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs index 3d52b9bdd7..4f6c3c7548 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs @@ -6,49 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] #[cpp_from(i32, new, value)] @@ -62,7 +20,7 @@ impl HasConstexprCtor { } pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { @@ -75,16 +33,6 @@ impl Clone for HasConstexprCtor { unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } } } -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -98,15 +46,11 @@ unsafe fn main_0() -> i32 { return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize].m; } }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); assert!(((unsafe { f.call() }) == (4))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const copyCount_0); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs index 09bdbc28d5..653affb1b1 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs @@ -6,49 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] #[cpp_from(i32, new, value)] @@ -62,7 +20,7 @@ impl HasConstexprCtor { } pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { @@ -75,16 +33,6 @@ impl Clone for HasConstexprCtor { unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } } } -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -98,15 +46,11 @@ unsafe fn main_0() -> i32 { return HasConstexprCtor::new({ 5 }).m; } }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const copyCount_0); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs index 11eab9f04d..b24fe03291 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs @@ -6,49 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] #[cpp_from(i32, new, value)] @@ -62,7 +20,7 @@ impl HasConstexprCtor { } pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { @@ -75,16 +33,6 @@ impl Clone for HasConstexprCtor { unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } } } -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -104,16 +52,12 @@ unsafe fn main_0() -> i32 { .m; } }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); assert!(((unsafe { f.call(true,) }) == (7))); assert!(((unsafe { f.call(false,) }) == (9))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const copyCount_0); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs index 37e0b2f7a3..01300a5bd5 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs @@ -6,49 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] #[cpp_from(i32, new, value)] @@ -62,7 +20,7 @@ impl HasConstexprCtor { } pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { @@ -75,17 +33,7 @@ impl Clone for HasConstexprCtor { unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } } } -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut left_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut left_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -97,24 +45,20 @@ unsafe fn main_0() -> i32 { let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { - (*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)).prefix_inc(); HasConstexprCtor::new({ 5 }) } .m; } }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)) == (0))); assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_5)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const left_5); + std::cell::LazyCell::force(&*&raw const copyCount_0); + std::cell::LazyCell::force(&*&raw const left_1); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs index 7a2b2bea66..95cacb98f4 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs @@ -48,44 +48,7 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut global_5: std::cell::LazyCell = +pub static mut global_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); pub fn main() { unsafe { @@ -94,16 +57,16 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)); + let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_4)); let mut f: FnPtr = FnPtr::::new(|| unsafe { (unsafe { - LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_5))) + LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_4))) }); }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); (unsafe { f.call() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)).uses) == (1))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut global_4)).uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); return 0; } @@ -112,6 +75,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const global_5); + std::cell::LazyCell::force(&*&raw const global_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs index 291746392d..22c0286d10 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs @@ -48,43 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -116,5 +79,4 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs index 7abe4b92d1..2e412490ba 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs @@ -6,49 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] #[cpp_from(i32, new, value)] @@ -62,7 +20,7 @@ impl HasConstexprCtor { } pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { @@ -75,16 +33,6 @@ impl Clone for HasConstexprCtor { unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } } } -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -102,15 +50,11 @@ unsafe fn main_0() -> i32 { return c.m; } ); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (1))); assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (2))); return 0; } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const copyCount_0); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs index 14c04b39a9..b03f0eb757 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs @@ -48,43 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] pub struct HasTwoMembers { @@ -122,7 +85,7 @@ unsafe fn main_0() -> i32 { b: LifetimeTracked::new(), }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); - let __decomp_5: *mut HasTwoMembers = &mut p; + let __decomp_4: *mut HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { unsafe { return ::std::mem::size_of::(); @@ -139,5 +102,4 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs index 57b22454a3..03b40c5401 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs @@ -48,43 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] pub struct HasMemberUsedInLambda { @@ -154,5 +117,4 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs index d911ab4bdf..698ef473c9 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs @@ -48,43 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] pub struct HasMemberUsedInLambda { @@ -134,5 +97,4 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); } diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs index 82edea7222..b2bdbdae9e 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs +++ b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs @@ -48,47 +48,10 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut noisy_calls_5: std::cell::LazyCell = +pub static mut noisy_calls_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn noisy_6() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)).prefix_inc(); +pub unsafe fn noisy_5() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)).prefix_inc(); return 1; } pub fn main() { @@ -106,10 +69,10 @@ unsafe fn main_0() -> i32 { assert!(!(false)); let mut n: i32 = 3; assert!(((n) == (3))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((unsafe { noisy_6() }) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_5)) == (1))); + assert!(((unsafe { noisy_5() }) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)) == (1))); return 0; } pub unsafe fn __cpp2rust_init_globals() { @@ -117,6 +80,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const noisy_calls_5); + std::cell::LazyCell::force(&*&raw const noisy_calls_4); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h b/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h index b1e10f34eb..7e37538241 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/h.h @@ -4,6 +4,7 @@ // one object, each constructed once and destroyed once. #pragma once +#include "../../../support/asserts-dtor-count-at-exit.h" #include "../../../support/lifetime-tracked.h" inline AssertsDtorCountAtExit check{2}; diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 466d5668ea..1f68bc14db 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -49,35 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { @@ -85,47 +56,47 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } thread_local!( - pub static check_5: Value = + pub static check_4: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); ); thread_local!( - pub static shared_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + pub static shared_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { pub fn instance() -> Ptr { - return local_7.with(|v| v.as_pointer()); + return local_6.with(|v| v.as_pointer()); } } thread_local!( - static local_7: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static local_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); - ({ b_use_8() }); + ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); - assert!(({ ({ (*shared_6.with(Value::clone).borrow()).uses } == 2) })); + assert!(({ ({ (*shared_5.with(Value::clone).borrow()).uses } == 2) })); assert!((({ HasInlineMembers::instance() }).with(|__s| __s.uses) == 2)); - assert!(((shared_6.with(|v| v.as_pointer())) == ({ b_shared_address_9() }))); - assert!((({ HasInlineMembers::instance() }) == ({ b_instance_address_10() }))); + assert!(((shared_5.with(|v| v.as_pointer())) == ({ b_shared_address_8() }))); + assert!((({ HasInlineMembers::instance() }) == ({ b_instance_address_9() }))); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); return 0; } -pub fn b_use_8() { - ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); +pub fn b_use_7() { + ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); } -pub fn b_shared_address_9() -> Ptr { - return (shared_6.with(|v| v.as_pointer())); +pub fn b_shared_address_8() -> Ptr { + return (shared_5.with(|v| v.as_pointer())); } -pub fn b_instance_address_10() -> Ptr { +pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } pub trait AssertsDtorCountAtExitImpl { @@ -136,15 +107,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -168,7 +130,6 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_5.with(|_| ()); - let _ = shared_6.with(|_| ()); + let _ = check_4.with(|_| ()); + let _ = shared_5.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index d4f32d0bbc..80f51d4a8d 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -85,19 +58,19 @@ impl AssertsDtorCountAtExit { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } -pub static mut check_5: std::cell::LazyCell = +pub static mut check_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } }); -pub static mut shared_6: std::cell::LazyCell = +pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct HasInlineMembers {} impl HasInlineMembers { pub unsafe fn instance() -> *mut LifetimeTracked { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut local_7)); + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut local_6)); } } -static mut local_7: std::cell::LazyCell = +static mut local_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); pub fn main() { unsafe { @@ -106,30 +79,30 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); - (unsafe { b_use_8() }); + (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)).uses) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).uses) == (2))); assert!((((*(unsafe { HasInlineMembers::instance() })).uses) == (2))); assert!( - ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) as *mut LifetimeTracked) - == (unsafe { b_shared_address_9() })) + == (unsafe { b_shared_address_8() })) ); - assert!(((unsafe { HasInlineMembers::instance() }) == (unsafe { b_instance_address_10() }))); + assert!(((unsafe { HasInlineMembers::instance() }) == (unsafe { b_instance_address_9() }))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); return 0; } -pub unsafe fn b_use_8() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); +pub unsafe fn b_use_7() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); } -pub unsafe fn b_shared_address_9() -> *mut LifetimeTracked { - return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) +pub unsafe fn b_shared_address_8() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) as *mut LifetimeTracked); } -pub unsafe fn b_instance_address_10() -> *mut LifetimeTracked { +pub unsafe fn b_instance_address_9() -> *mut LifetimeTracked { return (unsafe { HasInlineMembers::instance() }); } pub unsafe fn __cpp2rust_init_globals() { @@ -137,7 +110,6 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_5); - std::cell::LazyCell::force(&*&raw const shared_6); + std::cell::LazyCell::force(&*&raw const check_4); + std::cell::LazyCell::force(&*&raw const shared_5); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index a2ad002fd8..e5a214a38b 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -50,48 +50,13 @@ impl Default for LifetimeTracked { } } thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -thread_local!( - pub static member_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + pub static member_4: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct HasStaticMember_int_ {} thread_local!( - pub static member_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + pub static member_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] @@ -101,41 +66,24 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); - ({ b_use_int_7() }); - ({ b_use_long_8() }); - assert!(({ ({ (*member_5.with(Value::clone).borrow()).uses } == 2) })); - assert!(({ ({ (*member_6.with(Value::clone).borrow()).uses } == 1) })); - assert!(((member_5.with(|v| v.as_pointer())) == ({ b_int_address_9() }))); + ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ b_use_int_6() }); + ({ b_use_long_7() }); + assert!(({ ({ (*member_4.with(Value::clone).borrow()).uses } == 2) })); + assert!(({ ({ (*member_5.with(Value::clone).borrow()).uses } == 1) })); + assert!(((member_4.with(|v| v.as_pointer())) == ({ b_int_address_8() }))); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); return 0; } -pub fn b_use_int_7() { - ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); -} -pub fn b_use_long_8() { - ({ LifetimeTrackedImpl::use_(&member_6.with(|v| v.as_pointer())) }); -} -pub fn b_int_address_9() -> Ptr { - return (member_5.with(|v| v.as_pointer())); -} -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } +pub fn b_use_int_6() { + ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; +pub fn b_use_long_7() { + ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); } -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } +pub fn b_int_address_8() -> Ptr { + return (member_4.with(|v| v.as_pointer())); } pub trait LifetimeTrackedImpl { fn destructor(&self); @@ -160,7 +108,6 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); + let _ = member_4.with(|_| ()); let _ = member_5.with(|_| ()); - let _ = member_6.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index e6669be086..e82c2f66c3 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -48,49 +48,12 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub static mut member_5: std::cell::LazyCell = +pub static mut member_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct HasStaticMember_int_ {} -pub static mut member_6: std::cell::LazyCell = +pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] @@ -102,28 +65,28 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); - (unsafe { b_use_int_7() }); - (unsafe { b_use_long_8() }); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)).uses) == (2))); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_6)).uses) == (1))); + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { b_use_int_6() }); + (unsafe { b_use_long_7() }); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).uses) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)).uses) == (1))); assert!( - ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)) + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) as *mut LifetimeTracked) - == (unsafe { b_int_address_9() })) + == (unsafe { b_int_address_8() })) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); return 0; } -pub unsafe fn b_use_int_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); +pub unsafe fn b_use_int_6() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); } -pub unsafe fn b_use_long_8() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_6))) }); +pub unsafe fn b_use_long_7() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); } -pub unsafe fn b_int_address_9() -> *mut LifetimeTracked { - return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)) +pub unsafe fn b_int_address_8() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) as *mut LifetimeTracked); } pub unsafe fn __cpp2rust_init_globals() { @@ -131,7 +94,6 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); + std::cell::LazyCell::force(&*&raw const member_4); std::cell::LazyCell::force(&*&raw const member_5); - std::cell::LazyCell::force(&*&raw const member_6); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp index ed36ad1e2c..6462d0bf58 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp @@ -1,5 +1,6 @@ #include +#include "../../../support/asserts-dtor-count-at-exit.h" #include "h.h" AssertsDtorCountAtExit check{2}; diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index ab0f1c9828..5c75474fd6 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -49,61 +49,32 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -pub fn count_5() -> i32 { - return (*n_7.with(Value::clone).borrow_mut()).prefix_inc(); +pub fn count_4() -> i32 { + return (*n_6.with(Value::clone).borrow_mut()).prefix_inc(); } -pub fn count_8() -> i32 { - return (*n_10.with(Value::clone).borrow_mut()).prefix_inc(); +pub fn count_7() -> i32 { + return (*n_9.with(Value::clone).borrow_mut()).prefix_inc(); } thread_local!( - static t_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static t_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); thread_local!( - static n_7: Value = Rc::new(RefCell::new(0)); + static n_6: Value = Rc::new(RefCell::new(0)); ); thread_local!( - static t_9: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static t_8: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); thread_local!( - static n_10: Value = Rc::new(RefCell::new(0)); + static n_9: Value = Rc::new(RefCell::new(0)); ); thread_local!( - pub static check_11: Value = + pub static check_10: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); ); pub fn main() { @@ -112,20 +83,20 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((({ count_5() }) == 1)); - assert!((({ b_count_int_12() }) == 2)); - assert!((({ count_5() }) == 3)); + assert!((({ count_4() }) == 1)); + assert!((({ b_count_int_11() }) == 2)); + assert!((({ count_4() }) == 3)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); - assert!((({ count_8() }) == 1)); - assert!((({ b_count_long_13() }) == 2)); + assert!((({ count_7() }) == 1)); + assert!((({ b_count_long_12() }) == 2)); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); return 0; } -pub fn b_count_int_12() -> i32 { - return ({ count_5() }); +pub fn b_count_int_11() -> i32 { + return ({ count_4() }); } -pub fn b_count_long_13() -> i32 { - return ({ count_8() }); +pub fn b_count_long_12() -> i32 { + return ({ count_7() }); } pub trait AssertsDtorCountAtExitImpl { fn destructor(&self); @@ -135,15 +106,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -167,6 +129,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_11.with(|_| ()); + let _ = check_10.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index ed711f3ee7..5d4d3276ae 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -85,19 +58,19 @@ impl AssertsDtorCountAtExit { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } -pub unsafe fn count_5() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_7)).prefix_inc(); +pub unsafe fn count_4() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_6)).prefix_inc(); } -pub unsafe fn count_8() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_10)).prefix_inc(); +pub unsafe fn count_7() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_9)).prefix_inc(); } -static mut t_6: std::cell::LazyCell = +static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -static mut n_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -static mut t_9: std::cell::LazyCell = +static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -static mut n_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut check_11: std::cell::LazyCell = +static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut check_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } }); pub fn main() { unsafe { @@ -107,26 +80,25 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((unsafe { count_5() }) == (1))); - assert!(((unsafe { b_count_int_12() }) == (2))); - assert!(((unsafe { count_5() }) == (3))); + assert!(((unsafe { count_4() }) == (1))); + assert!(((unsafe { b_count_int_11() }) == (2))); + assert!(((unsafe { count_4() }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); - assert!(((unsafe { count_8() }) == (1))); - assert!(((unsafe { b_count_long_13() }) == (2))); + assert!(((unsafe { count_7() }) == (1))); + assert!(((unsafe { b_count_long_12() }) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); return 0; } -pub unsafe fn b_count_int_12() -> i32 { - return (unsafe { count_5() }); +pub unsafe fn b_count_int_11() -> i32 { + return (unsafe { count_4() }); } -pub unsafe fn b_count_long_13() -> i32 { - return (unsafe { count_8() }); +pub unsafe fn b_count_long_12() -> i32 { + return (unsafe { count_7() }); } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ctorCount_0); std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_11); + std::cell::LazyCell::force(&*&raw const check_10); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp index 00b3f9c39e..4e62fd8048 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-inline-function/a.cpp @@ -1,5 +1,6 @@ #include +#include "../../../support/asserts-dtor-count-at-exit.h" #include "h.h" AssertsDtorCountAtExit check{1}; diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 056d097c5f..4c66c42c17 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -49,49 +49,20 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -pub fn instance_5() -> Ptr { - return t_6.with(|v| v.as_pointer()); +pub fn instance_4() -> Ptr { + return t_5.with(|v| v.as_pointer()); } thread_local!( - static t_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static t_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); thread_local!( - pub static check_7: Value = + pub static check_6: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); ); pub fn main() { @@ -100,21 +71,21 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - ({ LifetimeTrackedImpl::use_(&({ instance_5() })) }); - ({ b_use_8() }); + ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); - assert!((({ instance_5() }).with(|__s| __s.uses) == 2)); - assert!((({ instance_5() }) == ({ b_address_9() }))); + assert!((({ instance_4() }).with(|__s| __s.uses) == 2)); + assert!((({ instance_4() }) == ({ b_address_8() }))); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); return 0; } -pub fn b_use_8() { - ({ LifetimeTrackedImpl::use_(&({ instance_5() })) }); +pub fn b_use_7() { + ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); } -pub fn b_address_9() -> Ptr { - return ({ instance_5() }); +pub fn b_address_8() -> Ptr { + return ({ instance_4() }); } pub trait AssertsDtorCountAtExitImpl { fn destructor(&self); @@ -124,15 +95,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -156,6 +118,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_7.with(|_| ()); + let _ = check_6.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index d8dc48c58d..66646518b4 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -85,12 +58,12 @@ impl AssertsDtorCountAtExit { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } -pub unsafe fn instance_5() -> *mut LifetimeTracked { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut t_6)); +pub unsafe fn instance_4() -> *mut LifetimeTracked { + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut t_5)); } -static mut t_6: std::cell::LazyCell = +static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -pub static mut check_7: std::cell::LazyCell = +pub static mut check_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); pub fn main() { unsafe { @@ -100,27 +73,26 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_5() }))) }); - (unsafe { b_use_8() }); + (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); - assert!((((*(unsafe { instance_5() })).uses) == (2))); - assert!(((unsafe { instance_5() }) == (unsafe { b_address_9() }))); + assert!((((*(unsafe { instance_4() })).uses) == (2))); + assert!(((unsafe { instance_4() }) == (unsafe { b_address_8() }))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); return 0; } -pub unsafe fn b_use_8() { - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_5() }))) }); +pub unsafe fn b_use_7() { + (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); } -pub unsafe fn b_address_9() -> *mut LifetimeTracked { - return (unsafe { instance_5() }); +pub unsafe fn b_address_8() -> *mut LifetimeTracked { + return (unsafe { instance_4() }); } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ctorCount_0); std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_7); + std::cell::LazyCell::force(&*&raw const check_6); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/h.h b/tests/std/basic/basic.def.odr/p15-inline-variable/h.h index c94ad19116..5128aff268 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/h.h +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/h.h @@ -3,6 +3,7 @@ // once and destroyed once. #pragma once +#include "../../../support/asserts-dtor-count-at-exit.h" #include "../../../support/lifetime-tracked.h" inline AssertsDtorCountAtExit check{1}; diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 58b59e2711..672ea8714b 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -49,35 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { @@ -85,31 +56,31 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } thread_local!( - pub static check_5: Value = + pub static check_4: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); ); thread_local!( - pub static shared_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + pub static shared_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); - ({ b_use_7() }); + ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ b_use_6() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); - assert!(({ ({ (*shared_6.with(Value::clone).borrow()).uses } == 2) })); - assert!(((shared_6.with(|v| v.as_pointer())) == ({ b_address_8() }))); + assert!(({ ({ (*shared_5.with(Value::clone).borrow()).uses } == 2) })); + assert!(((shared_5.with(|v| v.as_pointer())) == ({ b_address_7() }))); assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); return 0; } -pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&shared_6.with(|v| v.as_pointer())) }); +pub fn b_use_6() { + ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); } -pub fn b_address_8() -> Ptr { - return (shared_6.with(|v| v.as_pointer())); +pub fn b_address_7() -> Ptr { + return (shared_5.with(|v| v.as_pointer())); } pub trait AssertsDtorCountAtExitImpl { fn destructor(&self); @@ -119,15 +90,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -151,7 +113,6 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_5.with(|_| ()); - let _ = shared_6.with(|_| ()); + let _ = check_4.with(|_| ()); + let _ = shared_5.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index f499e645dc..2512f15427 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -85,9 +58,9 @@ impl AssertsDtorCountAtExit { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } -pub static mut check_5: std::cell::LazyCell = +pub static mut check_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); -pub static mut shared_6: std::cell::LazyCell = +pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); pub fn main() { unsafe { @@ -96,24 +69,24 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); - (unsafe { b_use_7() }); + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { b_use_6() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)).uses) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).uses) == (2))); assert!( - ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) as *mut LifetimeTracked) - == (unsafe { b_address_8() })) + == (unsafe { b_address_7() })) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); return 0; } -pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6))) }); +pub unsafe fn b_use_6() { + (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); } -pub unsafe fn b_address_8() -> *mut LifetimeTracked { - return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_6)) +pub unsafe fn b_address_7() -> *mut LifetimeTracked { + return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) as *mut LifetimeTracked); } pub unsafe fn __cpp2rust_init_globals() { @@ -121,7 +94,6 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_5); - std::cell::LazyCell::force(&*&raw const shared_6); + std::cell::LazyCell::force(&*&raw const check_4); + std::cell::LazyCell::force(&*&raw const shared_5); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp index d0f3160421..9190af58d3 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/a.cpp @@ -1,5 +1,6 @@ #include +#include "../../../support/asserts-dtor-count-at-exit.h" #include "h.h" AssertsDtorCountAtExit check{1}; diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 3a7ccf1428..302c9a8750 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -49,35 +49,6 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { @@ -88,10 +59,10 @@ pub struct AssertsDtorCountAtExit { #[byte_size(1)] pub struct X {} thread_local!( - static local_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static local_4: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); thread_local!( - pub static check_6: Value = + pub static check_5: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); ); pub fn main() { @@ -104,12 +75,12 @@ fn main_0() -> i32 { ({ XImpl::h(&x.as_pointer(), true, None) }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); - ({ b_call_7() }); + ({ b_call_6() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); return 0; } -pub fn b_call_7() { +pub fn b_call_6() { let x: Value = Rc::new(RefCell::new(::default())); ({ XImpl::h(&x.as_pointer(), true, None) }); } @@ -121,15 +92,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -155,7 +117,7 @@ impl XImpl for Ptr { fn h(&self, mut cond: bool, p: Option>) { let mut p: FnPtr = p.unwrap_or_else(|| { FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); }) }); if cond { @@ -170,6 +132,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_6.with(|_| ()); + let _ = check_5.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index 7011ff695b..e4dbd1b47e 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -94,7 +67,7 @@ impl X { Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), + &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }) @@ -106,9 +79,9 @@ impl X { } } } -static mut local_5: std::cell::LazyCell = +static mut local_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -pub static mut check_6: std::cell::LazyCell = +pub static mut check_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); pub fn main() { unsafe { @@ -122,12 +95,12 @@ unsafe fn main_0() -> i32 { (unsafe { X::h(&mut x, true, None) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); - (unsafe { b_call_7() }); + (unsafe { b_call_6() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); return 0; } -pub unsafe fn b_call_7() { +pub unsafe fn b_call_6() { let mut x: X = ::default(); (unsafe { X::h(&mut x, true, None) }); } @@ -136,6 +109,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_6); + std::cell::LazyCell::force(&*&raw const check_5); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp index 2688be6e7d..0b5e83750c 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/a.cpp @@ -1,5 +1,6 @@ #include +#include "../../../support/asserts-dtor-count-at-exit.h" #include "h.h" AssertsDtorCountAtExit check{1}; diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 1b0626969d..58a226d25a 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -49,48 +49,19 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -pub fn f_5(mut cond: bool, mut p: FnPtr) { +pub fn f_4(mut cond: bool, mut p: FnPtr) { if cond { ({ - f_5( + f_4( false, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_6.with(|v| v.as_pointer())) }); + ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); }), ) }); @@ -99,10 +70,10 @@ pub fn f_5(mut cond: bool, mut p: FnPtr) { } } thread_local!( - static local_6: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + static local_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); ); thread_local!( - pub static check_7: Value = + pub static check_6: Value = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); ); pub fn main() { @@ -111,16 +82,16 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - ({ f_5(true, FnPtr::::null()) }); + ({ f_4(true, FnPtr::::null()) }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); - ({ b_call_8() }); + ({ b_call_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); return 0; } -pub fn b_call_8() { - ({ f_5(true, FnPtr::::null()) }); +pub fn b_call_7() { + ({ f_4(true, FnPtr::::null()) }); } pub trait AssertsDtorCountAtExitImpl { fn destructor(&self); @@ -130,15 +101,6 @@ impl AssertsDtorCountAtExitImpl for Ptr { assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); } } -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} pub trait LifetimeTrackedImpl { fn destructor(&self); fn use_(&self); @@ -162,6 +124,5 @@ pub fn __cpp2rust_init_globals() { let _ = copyCount_1.with(|_| ()); let _ = dtorCount_2.with(|_| ()); let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); - let _ = check_7.with(|_| ()); + let _ = check_6.with(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 783e872355..997339451a 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -48,33 +48,6 @@ impl Default for LifetimeTracked { unsafe { LifetimeTracked::new() } } } -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct AssertsDtorCountAtExit { @@ -85,15 +58,15 @@ impl AssertsDtorCountAtExit { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); } } -pub unsafe fn f_5(mut cond: bool, mut p: Option) { +pub unsafe fn f_4(mut cond: bool, mut p: Option) { if cond { (unsafe { - f_5( + f_4( false, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_6)), + &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), ) }); }), @@ -103,9 +76,9 @@ pub unsafe fn f_5(mut cond: bool, mut p: Option) { (unsafe { (p).unwrap()() }); } } -static mut local_6: std::cell::LazyCell = +static mut local_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -pub static mut check_7: std::cell::LazyCell = +pub static mut check_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 1 } }); pub fn main() { unsafe { @@ -115,22 +88,21 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - (unsafe { f_5(true, None) }); + (unsafe { f_4(true, None) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); - (unsafe { b_call_8() }); + (unsafe { b_call_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); return 0; } -pub unsafe fn b_call_8() { - (unsafe { f_5(true, None) }); +pub unsafe fn b_call_7() { + (unsafe { f_4(true, None) }); } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ctorCount_0); std::cell::LazyCell::force(&*&raw const copyCount_1); std::cell::LazyCell::force(&*&raw const dtorCount_2); std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); - std::cell::LazyCell::force(&*&raw const check_7); + std::cell::LazyCell::force(&*&raw const check_6); } diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp index d27672aa1c..e9f1ad02fe 100644 --- a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp +++ b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp @@ -4,7 +4,7 @@ // odr-use arr, so [=] does not capture it. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" int main() { constexpr HasConstexprCtor arr[2] = {3, 4}; diff --git a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp index 52d9abccb6..879c2ce17b 100644 --- a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp +++ b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp @@ -4,7 +4,7 @@ // capture it. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" int main() { constexpr HasConstexprCtor k{5}; diff --git a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp index b8224780aa..35731e76c7 100644 --- a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp +++ b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp @@ -4,7 +4,7 @@ // Reading k.*pm does not odr-use k, so [=] does not capture it. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" int main() { constexpr HasConstexprCtor k{5}; diff --git a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp index 04bec2ef9c..8efaea7d9b 100644 --- a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp +++ b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp @@ -4,7 +4,7 @@ // odr-used, so [=] captures neither. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" int main() { constexpr HasConstexprCtor k1{7}; diff --git a/tests/std/basic/basic.def.odr/p3.8-comma.cpp b/tests/std/basic/basic.def.odr/p3.8-comma.cpp index ea9b5ba035..db017bded3 100644 --- a/tests/std/basic/basic.def.odr/p3.8-comma.cpp +++ b/tests/std/basic/basic.def.odr/p3.8-comma.cpp @@ -4,7 +4,7 @@ // the left operand is still evaluated. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" static int left; diff --git a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp index da02052280..591781df98 100644 --- a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp +++ b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp @@ -3,7 +3,7 @@ // type. Copying the constant k as a whole odr-uses it, so [=] captures it. #include -#include "../../support/lifetime-tracked.h" +#include "../../support/has-constexpr-ctor.h" int main() { constexpr HasConstexprCtor k{5}; diff --git a/tests/std/support/asserts-dtor-count-at-exit.h b/tests/std/support/asserts-dtor-count-at-exit.h new file mode 100644 index 0000000000..5e691219d2 --- /dev/null +++ b/tests/std/support/asserts-dtor-count-at-exit.h @@ -0,0 +1,9 @@ +#pragma once + +#include "lifetime-tracked.h" +#include + +struct AssertsDtorCountAtExit { + int expected; + ~AssertsDtorCountAtExit() { assert(LifetimeTracked::dtorCount == expected); } +}; diff --git a/tests/std/support/has-constexpr-ctor.h b/tests/std/support/has-constexpr-ctor.h new file mode 100644 index 0000000000..0b0f8a12d6 --- /dev/null +++ b/tests/std/support/has-constexpr-ctor.h @@ -0,0 +1,10 @@ +#pragma once + +struct HasConstexprCtor { + static inline int copyCount = 0; + + int m; + + constexpr HasConstexprCtor(int v) : m(v) {} + HasConstexprCtor(const HasConstexprCtor &o) : m(o.m) { ++copyCount; } +}; diff --git a/tests/std/support/lifetime-tracked.h b/tests/std/support/lifetime-tracked.h index 62a34ddce5..7e80c55a8c 100644 --- a/tests/std/support/lifetime-tracked.h +++ b/tests/std/support/lifetime-tracked.h @@ -1,7 +1,5 @@ #pragma once -#include - struct LifetimeTracked { static inline int ctorCount = 0; static inline int copyCount = 0; @@ -18,17 +16,3 @@ struct LifetimeTracked { ++useCount; } }; - -struct HasConstexprCtor { - static inline int copyCount = 0; - - int m; - - constexpr HasConstexprCtor(int v) : m(v) {} - HasConstexprCtor(const HasConstexprCtor &o) : m(o.m) { ++copyCount; } -}; - -struct AssertsDtorCountAtExit { - int expected; - ~AssertsDtorCountAtExit() { assert(LifetimeTracked::dtorCount == expected); } -};