public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6254] Fix diagnostic recursion ICE
@ 2022-01-05 12:11 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2022-01-05 12:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f2da9e26f5c0f04d48872938eff130e2028e75d3

commit r12-6254-gf2da9e26f5c0f04d48872938eff130e2028e75d3
Author: Nathan Sidwell <nathan@acm.org>
Date:   Tue Jan 4 12:45:36 2022 -0800

    Fix diagnostic recursion ICE
    
    The [with T = $TYPE] diagnostic machinery must not cause recursion. So let's
    not unilaterally warn about new alignment.  (template extracted from Open3D.)
    
            gcc/cp/
            * init.c (build_new_1): Check complain before alignment warning.
            gcc/testsuite/
            * g++.dg/diagnostic/recur-align.C: New.

Diff:
---
 gcc/cp/init.c                                 |  3 ++-
 gcc/testsuite/g++.dg/diagnostic/recur-align.C | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3f56ca4bf5e..9d616f3f5e9 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -3408,7 +3408,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
     = (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
        || varargs_function_p (alloc_fn));
 
-  if (warn_aligned_new
+  if (complain & tf_warning_or_error
+      && warn_aligned_new
       && !placement_allocation_fn_p
       && TYPE_ALIGN (elt_type) > malloc_alignment ()
       && (warn_aligned_new > 1
diff --git a/gcc/testsuite/g++.dg/diagnostic/recur-align.C b/gcc/testsuite/g++.dg/diagnostic/recur-align.C
new file mode 100644
index 00000000000..e7d4b9a17cc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/recur-align.C
@@ -0,0 +1,19 @@
+// ICE with diagnostic recursion
+// { dg-do compile { target { c++11_only || c++14_only } } }
+// { dg-options -Waligned-new }
+
+struct __attribute__ ((aligned(256))) Aligned
+{
+  int b;
+};
+
+template<typename T>
+auto Foo (const T* x) -> decltype (new T (*x))
+{
+  return new T (*x); // { dg-warning "with extended alignment" }
+}
+
+void Bar () {
+  Aligned y;
+  Foo (&y);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-05 12:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 12:11 [gcc r12-6254] Fix diagnostic recursion ICE 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).