Hi! On 2025-02-16T05:25:35+0000, "shynur ." <one.last.k...@outlook.com> wrote: > (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); > | ^~~~~~~~~~~~~~~
Ah, this mis-feature (in my opinion) of 'assert', that for '-DNDEBUG' it doesn't evaluate its argument... > This patch applies `__attribute__((unused))` to these variables, eliminating > the need for additional `-Wno` flag thus retaining the static checking > capabilities provided by GCC. That's OK, but two things needs changing, see below. > Thanks for reviewing! Thanks for improving GCC! :-) > From f23e1c52b34c403806f6a7c1b746a777c0fdf457 Mon Sep 17 00:00:00 2001 > From: shynur <shy...@outlook.com> > Date: Sun, 16 Feb 2025 13:08:30 +0800 > Subject: [PATCH] Avoid unused-variable-error when configured with > 'CFLAGS=-DNDEBUG'. As part of the Git commit message, please include a ChangeLog update (see <https://gcc.gnu.org/codingconventions.html#ChangeLogs> and 'git log'). Basically, 'contrib/gcc-changelog/git_check_commit.py --print-changelog' needs to accept your commit. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -2092,13 +2092,13 @@ 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); > + 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'.) Grüße Thomas