public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] warn-access: Fix handling of unnamed types [PR109804]
@ 2024-02-22 17:27 Andrew Pinski
  2024-05-08 17:13 ` Andrew Pinski
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Pinski @ 2024-02-22 17:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

This looks like an oversight of handling DEMANGLE_COMPONENT_UNNAMED_TYPE.
DEMANGLE_COMPONENT_UNNAMED_TYPE only has the u.s_number.number set while
the code expected newc.u.s_binary.left would be valid.
So this treats DEMANGLE_COMPONENT_UNNAMED_TYPE like we treat function paramaters
(DEMANGLE_COMPONENT_FUNCTION_PARAM) and template paramaters (DEMANGLE_COMPONENT_TEMPLATE_PARAM).

Note the code in the demangler does this when it sets DEMANGLE_COMPONENT_UNNAMED_TYPE:
      ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE;
      ret->u.s_number.number = num;

Committed as obvious after bootstrap/test on x86_64-linux-gnu
Will commit to other branches in a few days.

	PR tree-optimization/109804

gcc/ChangeLog:

	* gimple-ssa-warn-access.cc (new_delete_mismatch_p): Handle
	DEMANGLE_COMPONENT_UNNAMED_TYPE.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wmismatched-new-delete-8.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/gimple-ssa-warn-access.cc                 |  1 +
 .../g++.dg/warn/Wmismatched-new-delete-8.C    | 42 +++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index cd083ab2237..dedaae27b31 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -1701,6 +1701,7 @@ new_delete_mismatch_p (const demangle_component &newc,
 
     case DEMANGLE_COMPONENT_FUNCTION_PARAM:
     case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
+    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
       return newc.u.s_number.number != delc.u.s_number.number;
 
     case DEMANGLE_COMPONENT_CHARACTER:
diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C
new file mode 100644
index 00000000000..0ddc056c6df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C
@@ -0,0 +1,42 @@
+/* PR tree-optimization/109804 */
+/* { dg-do compile { target c++11 } } */
+/* { dg-options "-Wall" } */
+
+/* Here we used to ICE in new_delete_mismatch_p because
+   we didn't handle unnamed types from the demangler (DEMANGLE_COMPONENT_UNNAMED_TYPE). */
+
+template <typename T, typename ARGS>
+static inline T * construct_at(void *at, ARGS && args)
+{
+ struct Placeable : T
+ {
+  Placeable(ARGS && args) : T(args) { }
+  void * operator new (long unsigned int, void *ptr) { return ptr; }
+  void operator delete (void *, void *) { }
+ };
+ return new (at) Placeable(static_cast<ARGS &&>(args));
+}
+template <typename MT>
+struct Reconstructible
+{
+  char _space[sizeof(MT)];
+  Reconstructible() { }
+};
+template <typename MT>
+struct Constructible : Reconstructible<MT>
+{
+ Constructible(){}
+};
+struct A { };
+struct B
+{
+ Constructible<A> a { };
+ B(int) { }
+};
+Constructible<B> b { };
+void f()
+{
+  enum { ENUM_A = 1 };
+  enum { ENUM_B = 1 };
+  construct_at<B>(b._space, ENUM_B);
+}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [COMMITTED] warn-access: Fix handling of unnamed types [PR109804]
  2024-02-22 17:27 [COMMITTED] warn-access: Fix handling of unnamed types [PR109804] Andrew Pinski
@ 2024-05-08 17:13 ` Andrew Pinski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2024-05-08 17:13 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Thu, Feb 22, 2024 at 9:28 AM Andrew Pinski <quic_apinski@quicinc.com> wrote:
>
> This looks like an oversight of handling DEMANGLE_COMPONENT_UNNAMED_TYPE.
> DEMANGLE_COMPONENT_UNNAMED_TYPE only has the u.s_number.number set while
> the code expected newc.u.s_binary.left would be valid.
> So this treats DEMANGLE_COMPONENT_UNNAMED_TYPE like we treat function paramaters
> (DEMANGLE_COMPONENT_FUNCTION_PARAM) and template paramaters (DEMANGLE_COMPONENT_TEMPLATE_PARAM).
>
> Note the code in the demangler does this when it sets DEMANGLE_COMPONENT_UNNAMED_TYPE:
>       ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE;
>       ret->u.s_number.number = num;
>
> Committed as obvious after bootstrap/test on x86_64-linux-gnu
> Will commit to other branches in a few days.

Now committed (with the testcase fix backported too) to the GCC 12 branch.

Thanks,
Andrew Pinski

>
>         PR tree-optimization/109804
>
> gcc/ChangeLog:
>
>         * gimple-ssa-warn-access.cc (new_delete_mismatch_p): Handle
>         DEMANGLE_COMPONENT_UNNAMED_TYPE.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/warn/Wmismatched-new-delete-8.C: New test.
>
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
>  gcc/gimple-ssa-warn-access.cc                 |  1 +
>  .../g++.dg/warn/Wmismatched-new-delete-8.C    | 42 +++++++++++++++++++
>  2 files changed, 43 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C
>
> diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
> index cd083ab2237..dedaae27b31 100644
> --- a/gcc/gimple-ssa-warn-access.cc
> +++ b/gcc/gimple-ssa-warn-access.cc
> @@ -1701,6 +1701,7 @@ new_delete_mismatch_p (const demangle_component &newc,
>
>      case DEMANGLE_COMPONENT_FUNCTION_PARAM:
>      case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
> +    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
>        return newc.u.s_number.number != delc.u.s_number.number;
>
>      case DEMANGLE_COMPONENT_CHARACTER:
> diff --git a/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C
> new file mode 100644
> index 00000000000..0ddc056c6df
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-8.C
> @@ -0,0 +1,42 @@
> +/* PR tree-optimization/109804 */
> +/* { dg-do compile { target c++11 } } */
> +/* { dg-options "-Wall" } */
> +
> +/* Here we used to ICE in new_delete_mismatch_p because
> +   we didn't handle unnamed types from the demangler (DEMANGLE_COMPONENT_UNNAMED_TYPE). */
> +
> +template <typename T, typename ARGS>
> +static inline T * construct_at(void *at, ARGS && args)
> +{
> + struct Placeable : T
> + {
> +  Placeable(ARGS && args) : T(args) { }
> +  void * operator new (long unsigned int, void *ptr) { return ptr; }
> +  void operator delete (void *, void *) { }
> + };
> + return new (at) Placeable(static_cast<ARGS &&>(args));
> +}
> +template <typename MT>
> +struct Reconstructible
> +{
> +  char _space[sizeof(MT)];
> +  Reconstructible() { }
> +};
> +template <typename MT>
> +struct Constructible : Reconstructible<MT>
> +{
> + Constructible(){}
> +};
> +struct A { };
> +struct B
> +{
> + Constructible<A> a { };
> + B(int) { }
> +};
> +Constructible<B> b { };
> +void f()
> +{
> +  enum { ENUM_A = 1 };
> +  enum { ENUM_B = 1 };
> +  construct_at<B>(b._space, ENUM_B);
> +}
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-08 17:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 17:27 [COMMITTED] warn-access: Fix handling of unnamed types [PR109804] Andrew Pinski
2024-05-08 17:13 ` Andrew Pinski

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).