* [PATCH 1/2] c++: modules and non-dependent auto deduction
@ 2022-09-20 19:54 Patrick Palka
2022-09-20 19:54 ` [PATCH 2/2] c++: xtreme-header modules tests cleanups Patrick Palka
2022-09-20 20:02 ` [PATCH 1/2] c++: modules and non-dependent auto deduction Nathan Sidwell
0 siblings, 2 replies; 4+ messages in thread
From: Patrick Palka @ 2022-09-20 19:54 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, nathan, Patrick Palka
The modules streaming code seems to rely on the invariant that a
TEMPLATE_DECL and its DECL_TEMPLATE_RESULT have the same TREE_TYPE.
But for a templated VAR_DECL with deduced non-dependent type, the two
TREE_TYPEs end up diverging: cp_finish_decl deduces the type of the
initializer ahead of time and updates the TREE_TYPE of the VAR_DECL, but
neglects to update the corresponding TEMPLATE_DECL as well, which leads
to a "conflicting global module declaration" error for each of the
__phase_alignment decls in the below testcase (and for the xtreme-header
testcases if we try including <barrier>).
This patch makes cp_finish_decl update the TREE_TYPE of the corresponding
TEMPLATE_DECL so that the invariant is maintained.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?
gcc/cp/ChangeLog:
* decl.cc (cp_finish_decl): After updating the deduced type of a
VAR_DECL, also update the corresponding TEMPLATE_DECL if there
is one.
gcc/testsuite/ChangeLog:
* g++.dg/modules/auto-3.h: New test.
* g++.dg/modules/auto-3_a.H: New test.
* g++.dg/modules/auto-3_b.C: New test.
---
gcc/cp/decl.cc | 6 ++++++
gcc/testsuite/g++.dg/modules/auto-3.h | 10 ++++++++++
gcc/testsuite/g++.dg/modules/auto-3_a.H | 4 ++++
gcc/testsuite/g++.dg/modules/auto-3_b.C | 4 ++++
4 files changed, 24 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/modules/auto-3.h
create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_a.H
create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_b.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 070f673c3a2..80467c19254 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8180,6 +8180,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
return;
}
cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
+
+ /* Update the type of the corresponding TEMPLATE_DECL to match. */
+ if (DECL_LANG_SPECIFIC (decl)
+ && DECL_TEMPLATE_INFO (decl)
+ && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
+ TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
}
if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
diff --git a/gcc/testsuite/g++.dg/modules/auto-3.h b/gcc/testsuite/g++.dg/modules/auto-3.h
new file mode 100644
index 00000000000..f129433cbcb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-3.h
@@ -0,0 +1,10 @@
+template<class>
+struct __tree_barrier {
+ static const auto __phase_alignment_1 = 0;
+
+ template<class>
+ static const auto __phase_alignment_2 = 0;
+};
+
+template<class>
+inline auto __phase_alignment_3 = 0;
diff --git a/gcc/testsuite/g++.dg/modules/auto-3_a.H b/gcc/testsuite/g++.dg/modules/auto-3_a.H
new file mode 100644
index 00000000000..25a7a73e73e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-3_a.H
@@ -0,0 +1,4 @@
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "auto-3.h"
diff --git a/gcc/testsuite/g++.dg/modules/auto-3_b.C b/gcc/testsuite/g++.dg/modules/auto-3_b.C
new file mode 100644
index 00000000000..03b6d46f476
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-3_b.C
@@ -0,0 +1,4 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+#include "auto-3.h"
+import "auto-3_a.H";
--
2.38.0.rc0.52.gdda7228a83
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] c++: xtreme-header modules tests cleanups
2022-09-20 19:54 [PATCH 1/2] c++: modules and non-dependent auto deduction Patrick Palka
@ 2022-09-20 19:54 ` Patrick Palka
2022-09-20 20:02 ` Nathan Sidwell
2022-09-20 20:02 ` [PATCH 1/2] c++: modules and non-dependent auto deduction Nathan Sidwell
1 sibling, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2022-09-20 19:54 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, nathan, Patrick Palka
This adds some recently implemented C++20/23 library headers to the
xtreme-header tests as appropriate. Also, it looks like we can safely
re-add <execution> and remove the NO_ASSOCIATED_LAMBDA workaround.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
gcc/testsuite/ChangeLog:
* g++.dg/modules/xtreme-header-2.h: Include <execution>.
* g++.dg/modules/xtreme-header-6.h: Include <barrier>, <latch>,
<semaphore>, <source_location> and <syncstream>.
* g++.dg/modules/xtreme-header.h: Likewise. Remove
NO_ASSOCIATED_LAMBDA workaround. Include implemented C++23
library headers.
---
| 3 +-
| 10 ++--
| 60 +++++++------------
3 files changed, 29 insertions(+), 44 deletions(-)
--git a/gcc/testsuite/g++.dg/modules/xtreme-header-2.h b/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
index ded093e533c..dfe94aa6988 100644
--- a/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
+++ b/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
@@ -1,8 +1,7 @@
// Everything that transitively includes <ranges>
#include <algorithm>
-// FIXME: PR 97549
-// #include <execution>
+#include <execution>
#include <functional>
#include <future>
#include <memory>
--git a/gcc/testsuite/g++.dg/modules/xtreme-header-6.h b/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
index 85894b2b20a..8d024b69bac 100644
--- a/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
+++ b/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
@@ -1,22 +1,22 @@
// C++20 headers
#if __cplusplus > 201703
#include <version>
+#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_coroutines
#include <coroutine>
#endif
+#include <latch>
#include <numbers>
+#include <semaphore>
+#include <source_location>
#include <span>
#include <stop_token>
+#include <syncstream>
#if 0
// Unimplemented
-#include <barrier>
#include <format>
-#include <latch>
-#include <semaphore>
-#include <source_location>
-#include <syncstream>
#endif
#endif
--git a/gcc/testsuite/g++.dg/modules/xtreme-header.h b/gcc/testsuite/g++.dg/modules/xtreme-header.h
index 41302c780b5..124e2f82277 100644
--- a/gcc/testsuite/g++.dg/modules/xtreme-header.h
+++ b/gcc/testsuite/g++.dg/modules/xtreme-header.h
@@ -1,17 +1,8 @@
// All the headers!
-#if __cplusplus > 201703L
-// FIXME: if we include everything, something goes wrong with location
-// information. We used to not handle lambdas attached to global
-// vars, and this is a convienient flag to stop including everything.
-#define NO_ASSOCIATED_LAMBDA 1
-#endif
-
// C++ 17 and below
#if 1
-#if !NO_ASSOCIATED_LAMBDA
#include <algorithm>
-#endif
#include <any>
#include <array>
#include <atomic>
@@ -26,19 +17,12 @@
#include <cwctype>
#include <deque>
#include <exception>
-#if !NO_ASSOCIATED_LAMBDA
-// FIXME: PR 97549
-//#include <execution>
-#endif
+#include <execution>
#include <filesystem>
#include <forward_list>
#include <fstream>
-#if !NO_ASSOCIATED_LAMBDA
#include <functional>
-#endif
-#if !NO_ASSOCIATED_LAMBDA
#include <future>
-#endif
#include <initializer_list>
#include <iomanip>
#include <ios>
@@ -49,12 +33,8 @@
#include <list>
#include <locale>
#include <map>
-#if !NO_ASSOCIATED_LAMBDA
#include <memory>
-#endif
-#if !NO_ASSOCIATED_LAMBDA
#include <memory_resource>
-#endif
#include <mutex>
#include <new>
#include <numeric>
@@ -63,12 +43,8 @@
#include <queue>
#include <random>
#include <ratio>
-#if !NO_ASSOCIATED_LAMBDA
#include <regex>
-#endif
-#if !NO_ASSOCIATED_LAMBDA
#include <scoped_allocator>
-#endif
#include <set>
#include <shared_mutex>
#include <sstream>
@@ -78,9 +54,7 @@
#include <string>
#include <string_view>
#include <system_error>
-#if !NO_ASSOCIATED_LAMBDA
#include <thread>
-#endif
#include <tuple>
#include <type_traits>
#include <typeindex>
@@ -88,9 +62,7 @@
#include <unordered_map>
#include <unordered_set>
#include <utility>
-#if !NO_ASSOCIATED_LAMBDA
#include <valarray>
-#endif
#include <variant>
#include <vector>
#endif
@@ -119,26 +91,40 @@
#if __cplusplus > 201703
#if 1
#include <version>
+#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_coroutines
#include <coroutine>
#endif
-#if !NO_ASSOCIATED_LAMBDA
-#include <ranges>
-#endif
+#include <latch>
#include <numbers>
+#include <ranges>
+#include <semaphore>
+#include <source_location>
#include <span>
#include <stop_token>
+#include <syncstream>
#if 0
// Unimplemented
-#include <barrier>
#include <format>
-#include <latch>
-#include <semaphore>
-#include <source_location>
-#include <syncstream>
#endif
#endif
#endif
+
+// C++23
+#if __cplusplus > 202002L
+#include <expected>
+#include <spanstream>
+#include <stacktrace>
+#if 0
+// Unimplemented
+#include <flat_map>
+#include <flat_set>
+#include <generator>
+#include <mdspan>
+#include <print>
+#endif
+#endif
+
--
2.38.0.rc0.52.gdda7228a83
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] c++: modules and non-dependent auto deduction
2022-09-20 19:54 [PATCH 1/2] c++: modules and non-dependent auto deduction Patrick Palka
2022-09-20 19:54 ` [PATCH 2/2] c++: xtreme-header modules tests cleanups Patrick Palka
@ 2022-09-20 20:02 ` Nathan Sidwell
1 sibling, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2022-09-20 20:02 UTC (permalink / raw)
To: Patrick Palka, gcc-patches; +Cc: jason
On 9/20/22 15:54, Patrick Palka wrote:
> The modules streaming code seems to rely on the invariant that a
> TEMPLATE_DECL and its DECL_TEMPLATE_RESULT have the same TREE_TYPE.
It does indeed.
> But for a templated VAR_DECL with deduced non-dependent type, the two
> TREE_TYPEs end up diverging: cp_finish_decl deduces the type of the
> initializer ahead of time and updates the TREE_TYPE of the VAR_DECL, but
> neglects to update the corresponding TEMPLATE_DECL as well, which leads
> to a "conflicting global module declaration" error for each of the
> __phase_alignment decls in the below testcase (and for the xtreme-header
> testcases if we try including <barrier>).
>
> This patch makes cp_finish_decl update the TREE_TYPE of the corresponding
> TEMPLATE_DECL so that the invariant is maintained >
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
Ok, thanks
>
> gcc/cp/ChangeLog:
>
> * decl.cc (cp_finish_decl): After updating the deduced type of a
> VAR_DECL, also update the corresponding TEMPLATE_DECL if there
> is one.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/auto-3.h: New test.
> * g++.dg/modules/auto-3_a.H: New test.
> * g++.dg/modules/auto-3_b.C: New test.
> ---
> gcc/cp/decl.cc | 6 ++++++
> gcc/testsuite/g++.dg/modules/auto-3.h | 10 ++++++++++
> gcc/testsuite/g++.dg/modules/auto-3_a.H | 4 ++++
> gcc/testsuite/g++.dg/modules/auto-3_b.C | 4 ++++
> 4 files changed, 24 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/modules/auto-3.h
> create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_a.H
> create mode 100644 gcc/testsuite/g++.dg/modules/auto-3_b.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 070f673c3a2..80467c19254 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -8180,6 +8180,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
> return;
> }
> cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
> +
> + /* Update the type of the corresponding TEMPLATE_DECL to match. */
> + if (DECL_LANG_SPECIFIC (decl)
> + && DECL_TEMPLATE_INFO (decl)
> + && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
> + TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
> }
>
> if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3.h b/gcc/testsuite/g++.dg/modules/auto-3.h
> new file mode 100644
> index 00000000000..f129433cbcb
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3.h
> @@ -0,0 +1,10 @@
> +template<class>
> +struct __tree_barrier {
> + static const auto __phase_alignment_1 = 0;
> +
> + template<class>
> + static const auto __phase_alignment_2 = 0;
> +};
> +
> +template<class>
> +inline auto __phase_alignment_3 = 0;
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3_a.H b/gcc/testsuite/g++.dg/modules/auto-3_a.H
> new file mode 100644
> index 00000000000..25a7a73e73e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3_a.H
> @@ -0,0 +1,4 @@
> +// { dg-additional-options "-fmodule-header" }
> +// { dg-module-cmi {} }
> +
> +#include "auto-3.h"
> diff --git a/gcc/testsuite/g++.dg/modules/auto-3_b.C b/gcc/testsuite/g++.dg/modules/auto-3_b.C
> new file mode 100644
> index 00000000000..03b6d46f476
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/auto-3_b.C
> @@ -0,0 +1,4 @@
> +// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
> +
> +#include "auto-3.h"
> +import "auto-3_a.H";
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] c++: xtreme-header modules tests cleanups
2022-09-20 19:54 ` [PATCH 2/2] c++: xtreme-header modules tests cleanups Patrick Palka
@ 2022-09-20 20:02 ` Nathan Sidwell
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2022-09-20 20:02 UTC (permalink / raw)
To: Patrick Palka, gcc-patches; +Cc: jason
On 9/20/22 15:54, Patrick Palka wrote:
> This adds some recently implemented C++20/23 library headers to the
> xtreme-header tests as appropriate. Also, it looks like we can safely
> re-add <execution> and remove the NO_ASSOCIATED_LAMBDA workaround.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
cool, more bits working. thanks!
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/xtreme-header-2.h: Include <execution>.
> * g++.dg/modules/xtreme-header-6.h: Include <barrier>, <latch>,
> <semaphore>, <source_location> and <syncstream>.
> * g++.dg/modules/xtreme-header.h: Likewise. Remove
> NO_ASSOCIATED_LAMBDA workaround. Include implemented C++23
> library headers.
> ---
> .../g++.dg/modules/xtreme-header-2.h | 3 +-
> .../g++.dg/modules/xtreme-header-6.h | 10 ++--
> gcc/testsuite/g++.dg/modules/xtreme-header.h | 60 +++++++------------
> 3 files changed, 29 insertions(+), 44 deletions(-)
>
> diff --git a/gcc/testsuite/g++.dg/modules/xtreme-header-2.h b/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
> index ded093e533c..dfe94aa6988 100644
> --- a/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
> +++ b/gcc/testsuite/g++.dg/modules/xtreme-header-2.h
> @@ -1,8 +1,7 @@
> // Everything that transitively includes <ranges>
>
> #include <algorithm>
> -// FIXME: PR 97549
> -// #include <execution>
> +#include <execution>
> #include <functional>
> #include <future>
> #include <memory>
> diff --git a/gcc/testsuite/g++.dg/modules/xtreme-header-6.h b/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
> index 85894b2b20a..8d024b69bac 100644
> --- a/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
> +++ b/gcc/testsuite/g++.dg/modules/xtreme-header-6.h
> @@ -1,22 +1,22 @@
> // C++20 headers
> #if __cplusplus > 201703
> #include <version>
> +#include <barrier>
> #include <bit>
> #include <compare>
> #include <concepts>
> #if __cpp_coroutines
> #include <coroutine>
> #endif
> +#include <latch>
> #include <numbers>
> +#include <semaphore>
> +#include <source_location>
> #include <span>
> #include <stop_token>
> +#include <syncstream>
> #if 0
> // Unimplemented
> -#include <barrier>
> #include <format>
> -#include <latch>
> -#include <semaphore>
> -#include <source_location>
> -#include <syncstream>
> #endif
> #endif
> diff --git a/gcc/testsuite/g++.dg/modules/xtreme-header.h b/gcc/testsuite/g++.dg/modules/xtreme-header.h
> index 41302c780b5..124e2f82277 100644
> --- a/gcc/testsuite/g++.dg/modules/xtreme-header.h
> +++ b/gcc/testsuite/g++.dg/modules/xtreme-header.h
> @@ -1,17 +1,8 @@
> // All the headers!
>
> -#if __cplusplus > 201703L
> -// FIXME: if we include everything, something goes wrong with location
> -// information. We used to not handle lambdas attached to global
> -// vars, and this is a convienient flag to stop including everything.
> -#define NO_ASSOCIATED_LAMBDA 1
> -#endif
> -
> // C++ 17 and below
> #if 1
> -#if !NO_ASSOCIATED_LAMBDA
> #include <algorithm>
> -#endif
> #include <any>
> #include <array>
> #include <atomic>
> @@ -26,19 +17,12 @@
> #include <cwctype>
> #include <deque>
> #include <exception>
> -#if !NO_ASSOCIATED_LAMBDA
> -// FIXME: PR 97549
> -//#include <execution>
> -#endif
> +#include <execution>
> #include <filesystem>
> #include <forward_list>
> #include <fstream>
> -#if !NO_ASSOCIATED_LAMBDA
> #include <functional>
> -#endif
> -#if !NO_ASSOCIATED_LAMBDA
> #include <future>
> -#endif
> #include <initializer_list>
> #include <iomanip>
> #include <ios>
> @@ -49,12 +33,8 @@
> #include <list>
> #include <locale>
> #include <map>
> -#if !NO_ASSOCIATED_LAMBDA
> #include <memory>
> -#endif
> -#if !NO_ASSOCIATED_LAMBDA
> #include <memory_resource>
> -#endif
> #include <mutex>
> #include <new>
> #include <numeric>
> @@ -63,12 +43,8 @@
> #include <queue>
> #include <random>
> #include <ratio>
> -#if !NO_ASSOCIATED_LAMBDA
> #include <regex>
> -#endif
> -#if !NO_ASSOCIATED_LAMBDA
> #include <scoped_allocator>
> -#endif
> #include <set>
> #include <shared_mutex>
> #include <sstream>
> @@ -78,9 +54,7 @@
> #include <string>
> #include <string_view>
> #include <system_error>
> -#if !NO_ASSOCIATED_LAMBDA
> #include <thread>
> -#endif
> #include <tuple>
> #include <type_traits>
> #include <typeindex>
> @@ -88,9 +62,7 @@
> #include <unordered_map>
> #include <unordered_set>
> #include <utility>
> -#if !NO_ASSOCIATED_LAMBDA
> #include <valarray>
> -#endif
> #include <variant>
> #include <vector>
> #endif
> @@ -119,26 +91,40 @@
> #if __cplusplus > 201703
> #if 1
> #include <version>
> +#include <barrier>
> #include <bit>
> #include <compare>
> #include <concepts>
> #if __cpp_coroutines
> #include <coroutine>
> #endif
> -#if !NO_ASSOCIATED_LAMBDA
> -#include <ranges>
> -#endif
> +#include <latch>
> #include <numbers>
> +#include <ranges>
> +#include <semaphore>
> +#include <source_location>
> #include <span>
> #include <stop_token>
> +#include <syncstream>
> #if 0
> // Unimplemented
> -#include <barrier>
> #include <format>
> -#include <latch>
> -#include <semaphore>
> -#include <source_location>
> -#include <syncstream>
> #endif
> #endif
> #endif
> +
> +// C++23
> +#if __cplusplus > 202002L
> +#include <expected>
> +#include <spanstream>
> +#include <stacktrace>
> +#if 0
> +// Unimplemented
> +#include <flat_map>
> +#include <flat_set>
> +#include <generator>
> +#include <mdspan>
> +#include <print>
> +#endif
> +#endif
> +
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-20 20:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 19:54 [PATCH 1/2] c++: modules and non-dependent auto deduction Patrick Palka
2022-09-20 19:54 ` [PATCH 2/2] c++: xtreme-header modules tests cleanups Patrick Palka
2022-09-20 20:02 ` Nathan Sidwell
2022-09-20 20:02 ` [PATCH 1/2] c++: modules and non-dependent auto deduction Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).