https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110373
Bug ID: 110373 Summary: __builtin_object_size does not recognize subarrays in multi-dimensional arrays Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: siddhesh at gcc dot gnu.org Target Milestone: --- const char example[][32] = { "abcd", "xyzt", "1234", "5678" }; __SIZE_TYPE__ foo (void) { return __builtin_dynamic_object_size(example[1], 1); } $ gcc/cc1 -quiet -O -o - ~/src/random/fortify-module/fortify-module1.c .file "fortify-module1.c" .text .globl foo .type foo, @function foo: .LFB0: .cfi_startproc movl $96, %eax ret .cfi_endproc .LFE0: .size foo, .-foo .globl example .section .rodata .align 32 .type example, @object .size example, 128 example: .string "abcd" .zero 27 .string "xyzt" .zero 27 .string "1234" .zero 27 .string "5678" .zero 27 .ident "GCC: (GNU) 14.0.0 20230622 (experimental)" .section .note.GNU-stack,"",@progbits Clang returns 32 instead, recognizing the subarray correctly. This appears to be happening very early on in the frontend; addr_object_size doesn't see that this is a subarray reference since it only compares the pt_var with the operand of the ADDR_EXPR. If pt_var is an ARRAY_REF, it should also additionally see if this is a subarray reference.