https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109354
Bug ID: 109354 Summary: [arm32] Parameter stored on stack gets wrong debug info with -Og or higher Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: sirl at gcc dot gnu.org Target Milestone: --- Hi, this small testcase class c1 { struct s1 { unsigned int m_n1; }; struct s2 { s1 sM1; s1 sM2; }; s2 m_s2; int m_bsoM1; int m_bsoM2; struct OnOffP { unsigned int count; int so; s1 *ts; }; void OnI(struct OnOffP *p); void OffI(struct OnOffP *p); virtual void OnOff(unsigned int nCount, bool bOff, bool bM1); }; void c1::OnOff(unsigned int nCount, bool bOff, bool bM1) { struct OnOffP eOffP; // 2 variables only added to better show the behaviour volatile int xxx = 0xaa00aa; volatile int xyz = 0xab00ab; eOffP.count = nCount; eOffP.so = m_bsoM2; eOffP.ts = &(m_s2.sM2); if (bM1) { eOffP.so = m_bsoM1; eOffP.ts = &(m_s2.sM1); } if (!bOff) OnI(&eOffP); else OffI(&eOffP); xxx++; xyz++; } compiled with "arm-none-eabi-g++-13 -c -mcpu=cortex-r5 -mfpu=vfpv3-d16 -mfloat-abi=hard -fno-exceptions -g -Og" generates wrong debug info for the nCount parameter. llvm-dwarfdump-16.0.0 --name nCount --name eOffP -name xyz arm-debug-info-bug1.o shows: arm-debug-info-bug1.o: file format elf32-littlearm 0x000001c5: DW_TAG_formal_parameter DW_AT_name ("nCount") DW_AT_decl_file ("arm-debug-info-bug1.cpp") DW_AT_decl_line (31) DW_AT_decl_column (0x1d) DW_AT_type (0x0000002c "unsigned int") DW_AT_location (0x0000005c: [0x00000000, 0x00000028): DW_OP_reg1 R1 [0x00000028, 0x00000054): DW_OP_fbreg -28 [0x00000054, 0x00000057): DW_OP_breg1 R1+0 [0x00000057, 0x00000078): DW_OP_GNU_entry_value(<decoding error> f5 01 25 f7 2c f7 00 9f [0x00000078, 0x0000007c): DW_OP_fbreg -28 [0x0000007c, 0x0000007f): DW_OP_breg1 R1+0 [0x0000007f, 0x00000084): DW_OP_GNU_entry_value(<decoding error> f5 01 25 f7 2c f7 00 9f) DW_AT_GNU_locviews (0x0000004e) 0x00000201: DW_TAG_variable DW_AT_name ("eOffP") DW_AT_decl_file ("arm-debug-info-bug1.cpp") DW_AT_decl_line (33) DW_AT_decl_column (0x10) DW_AT_type (0x0000008b "c1::OnOffP") DW_AT_location (DW_OP_fbreg -20) 0x0000021f: DW_TAG_variable DW_AT_name ("xyz") DW_AT_decl_file ("arm-debug-info-bug1.cpp") DW_AT_decl_line (35) DW_AT_decl_column (0x0f) DW_AT_type (0x00000163 "volatile int") DW_AT_location (DW_OP_fbreg -28) So according to this the debug info says that "nCount" (DW_OP_fbreg -28) overlaps with "xyz" (DW_OP_fbreg -28), when in fact it overlaps with "eOffP.count" (DW_OP_fbreg -20). It's unclear if this is caused by wrong debug info generation, wrong lifetime or both. When we see cases like this, a common point seems to be that the offset difference is always 8 (-20 vs -28). The bug seems to be long-standing though, we saw it with 10.4.0, 12.2.1 and 13.0.1 so far.