https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128330
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Dominic Plunkett <[email protected]>: https://gcc.gnu.org/g:9a03c9508aaadd96b5b38380ba16b64a4ac6ece0 commit r17-6827-g9a03c9508aaadd96b5b38380ba16b64a4ac6ece0 Author: Dominic P <[email protected]> Date: Sat Nov 28 11:15:37 2026 +0000 cfgexpand: Protect arrays of any char-precision integer type [PR128330] stack_protect_classify_type treats an array as a character array only when its element type is char_type_node, signed_char_type_node or unsigned_char_type_node. After LTO streaming a plain char element is not char_type_node, so -flto -fstack-protector leaves such functions unguarded. Arrays of char8_t, std::byte, _BitInt(8) or enums with a char underlying type, multi-dimensional char arrays and arrays of structures holding char arrays are missed too, although a one-dimensional char array or a single such structure is guarded. Use the innermost element type: an integral type with the precision of char makes a character array; classify any other element type recursively. Testing the precision rather than the size keeps arrays of C and C++ bool and of _BitInt(N) with N below the char precision unguarded, as before; Ada's Boolean has the precision of char, so its arrays are now guarded. This also guards a VLA whose size CCP folds to a constant, e.g. "int n = 16; char a[n];", at -O1 and above as at -O0: CCP replaces it with an array of an unsigned BITS_PER_UNIT-bit type that is not unsigned_char_type_node. Assisted-by: Claude Opus 5.5 (Anthropic) Signed-off-by: Dominic P <[email protected]> PR lto/128330 gcc/ChangeLog: * cfgexpand.cc (stack_protect_classify_type): Look through nested array types. Treat arrays of any integral type with the precision of char as character arrays. Classify other element types recursively. gcc/testsuite/ChangeLog: * g++.dg/fstack-protector-char8.C: New test. * gcc.dg/fstack-protector-bitint.c: New test. * gcc.dg/lto/pr128330_0.c: New test.
