https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129285

            Bug ID: 129285
           Summary: -flto-incremental does not invalidate LTRANS cache
                    when #pragma GCC diagnostic changes
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luolongjuna at gmail dot com
  Target Milestone: ---

While exploring the LTRANS cache code, I found this problem. "#pragma GCC
diagnostic" is recorded separately (-fltrans-linemap-file=), and the SHA1 of
the LTRANS cache is only calculated from ltrans0.o itself. If the pragma
changes, GCC may still reuse the outdated cache file.

Reduced case:

mkdir cache
cat > main.c <<EOF
#pragma GCC diagnostic ignored "-Wstringop-overflow"
char a[4];
int main(void) { __builtin_memset(a, 0, 8); return a[0]; }
EOF

# 1. Build with the warning ignored
gcc -O2 -flto -flto-incremental=cache main.c -o app
# -> exit 0

# 2. 'ignored' -> 'error', rebuild with cache
sed -i 's/ignored/error/' main.c
gcc -O2 -flto -flto-incremental=cache main.c -o app
# -> exit 0  (-v shows "LTRANS: recompiling 0/1")

# 3. Same build without cache
gcc -O2 -flto main.c -o app
# -> main.c:3:18: error: '__builtin_memset' writing 8 bytes into a region of
size 4 overflows the destination [-Werror=stringop-overflow=]

Reproduced on x86_64 Linux with GCC 17 trunk (cdb8a10e1a8).

Reply via email to