From d9039d3d5b410075e2afa3a5a635f7399f072edd Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Wed, 7 Jun 2023 16:24:26 +0200
Subject: [PATCH] Tighten 'dg-warning' alternatives in
 'c-c++-common/Wfree-nonheap-object{,-2,-3}.c'

..., added in commit fe7f75cf16783589eedbab597e6d0b8d35d7e470
"Correct/improve maybe_emit_free_warning (PR middle-end/98166, PR c++/57111, PR middle-end/98160)".

These use alternatives like, for example, "AB|CDE|FG", but what really must've
been meant is "A(B|C)D(E|F)G".  The former variant also does "work": it matches
any of "AB", or "CDE", or "FG", which are components of the latter variant.
(That means, the former variant matches too loosely.)

	gcc/testsuite/
	* c-c++-common/Wfree-nonheap-object-2.c: Tighten 'dg-warning'
	alternatives.
	* c-c++-common/Wfree-nonheap-object-3.c: Likewise.
	* c-c++-common/Wfree-nonheap-object.c: Likewise.
---
 gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c | 2 +-
 gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c | 6 +++---
 gcc/testsuite/c-c++-common/Wfree-nonheap-object.c   | 8 ++++----
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c b/gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c
index 0aedf1babbc..a2dbd181e33 100644
--- a/gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c
+++ b/gcc/testsuite/c-c++-common/Wfree-nonheap-object-2.c
@@ -32,7 +32,7 @@ void test_nowarn_int (int n)
 inline void
 dealloc_long (long *p)
 {
-  __builtin_free (p);         // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  __builtin_free (p);         // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 }
 
 __attribute__ ((malloc (dealloc_long)))
diff --git a/gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c b/gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c
index 41a5b50362e..8f20de8455f 100644
--- a/gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c
+++ b/gcc/testsuite/c-c++-common/Wfree-nonheap-object-3.c
@@ -22,7 +22,7 @@ void test_nowarn_int (int n)
 
   {
     int *p = alloc_int (n);
-    __builtin_free (p + 1);   // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+    __builtin_free (p + 1);   // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
   }
 }
 
@@ -42,7 +42,7 @@ void test_nowarn_long (int n)
 
   {
     long *p = alloc_long (n);
-    dealloc_long (p + 1);     // { dg-warning "'dealloc_long' called on pointer 'p|<unknown>' with nonzero offset" }
+    dealloc_long (p + 1);     // { dg-warning "'dealloc_long' called on pointer '(p|<unknown>)' with nonzero offset" }
   }
 }
 
@@ -50,7 +50,7 @@ void test_nowarn_long (int n)
 inline __attribute__ ((always_inline)) void
 dealloc_float (float *p)      // { dg-message "deallocation function declared here" }
 {
-  __builtin_free (p);         // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  __builtin_free (p);         // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 }
 
 __attribute__ ((malloc (dealloc_float)))
diff --git a/gcc/testsuite/c-c++-common/Wfree-nonheap-object.c b/gcc/testsuite/c-c++-common/Wfree-nonheap-object.c
index dfbb296e9a7..5f1e3fb28f3 100644
--- a/gcc/testsuite/c-c++-common/Wfree-nonheap-object.c
+++ b/gcc/testsuite/c-c++-common/Wfree-nonheap-object.c
@@ -37,14 +37,14 @@ void test_nowarm (void)
 void test_warn (void)
 {
   char *p = f ();
-  free (p + 1);               // { dg-warning "'free|void free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  free (p + 1);               // { dg-warning "'(free|void free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 
   p = g ();
-  free (p + 2);               // { dg-warning "'free|void free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  free (p + 2);               // { dg-warning "'(free|void free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 
   p = f ();
-  __builtin_free (p + 3);     // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  __builtin_free (p + 3);     // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 
   p = g ();
-  __builtin_free (p + 4);     // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
+  __builtin_free (p + 4);     // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
 }
-- 
2.34.1

