[PATCH] libgomp: avoid unused-variable-error when configured with CFLAGS=-DNDEBUG

2025-01-08 Thread shynur .
>From 929fb2091ffe50a35a1b2dae1f1ce20357bc435b Mon Sep 17 00:00:00 2001
From: shynur 
Date: Thu, 9 Jan 2025 14:11:38 +0800
Subject: [PATCH] Avoid unused-variable-error when configured with
 'CFLAGS=-DNDEBUG'

---
 libgomp/target.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libgomp/target.c b/libgomp/target.c
index 9fc51b160f0..dbc4535b96f 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -2092,8 +2092,9 @@ gomp_unmap_vars_internal (struct target_mem_desc *tgt, 
bool do_copyfrom,
tgt->list[i].length);
   if (do_remove)
{
- struct target_mem_desc *k_tgt = k->tgt;
- bool is_tgt_unmapped = gomp_remove_var (devicep, k);
+ struct target_mem_desc *k_tgt __attribute__((unused)) = k->tgt;
+ bool is_tgt_unmapped __attribute__((unused))
+   = gomp_remove_var (devicep, k);
  /* It would be bad if TGT got unmapped while we're still iterating
 over its LIST_COUNT, and also expect to use it in the following
 code.  */
-- 
2.45.2



Re: [PATCH] libgomp: avoid unused-variable-error when configured with CFLAGS=-DNDEBUG

2025-02-15 Thread shynur .
(The *new* patch is attached.)

Hi, Jakub and Thomas~  I found some problems when compiling GCC, and it turns
out it was related to libgomp.

$ git clone ...
$ mkdir gcc-build
$ cd gcc-build

If I configure GCC with

$ CC=gcc-14 CXX=g++-14 CFLAGS=-DNDEBUG ../gcc/configure 
--enable-languages=c++ --disable-multilib --disable-checking 
--disable-bootstrap --program-suffix=-test

Then

$ make -j2

It will fail because

../../../gcc/libgomp/oacc-mem.c: In function ‘acc_unmap_data’:
../../../gcc/libgomp/oacc-mem.c:483:8: error: unused variable 
‘is_tgt_unmapped’ [-Werror=unused-variable]
  483 |   bool is_tgt_unmapped = gomp_remove_var (acc_dev, n);
  |^~~
.
.
.

This patch applies `__attribute__((unused))` to these variables, eliminating
the need for additional `-Wno` flag thus retaining the static checking
capabilities provided by GCC.

Thanks for reviewing!

0001-Avoid-unused-variable-error-when-configured-with-CFL.patch
Description: 0001-Avoid-unused-variable-error-when-configured-with-CFL.patch


Re: [PATCH] libgomp: avoid unused-variable-error when configured with CFLAGS=-DNDEBUG

2025-02-17 Thread shynur .
> As part of the Git commit message, please include a ChangeLog update (see
>  and 'git log').

I've written a new patch which is attached.

> Basically, 'contrib/gcc-changelog/git_check_commit.py --print-changelog'
> needs to accept your commit.

This time it passed the check!  Thank you, Thomas!

>> -   struct target_mem_desc *k_tgt = k->tgt;
>> -   bool is_tgt_unmapped = gomp_remove_var (devicep, k);
>> +   bool is_tgt_unmapped __attribute__((unused))
>> + = gomp_remove_var (devicep, k);
>>  /* It would be bad if TGT got unmapped while we're still iterating
>> over its LIST_COUNT, and also expect to use it in the following
>> code.  */
>>  assert (!is_tgt_unmapped
>> -   || k_tgt != tgt);
>> +   || k->tgt != tgt);
>>}
>
> Please check: if I remember correctly, it's no longer valid to dereference
> 'k->tgt' after 'gomp_remove_var (devicep, k);'?  (That's why we preserve the
> former as 'k_tgt'.)

My mistake.  I'm sorry.

0001-Add-__attribute__-unused-to-variables-used-only-in-a.patch
Description: 0001-Add-__attribute__-unused-to-variables-used-only-in-a.patch