Issue 91542
Summary Incorrect of debug informaiton of a structure variable compiled with "clang -g -O3"
Labels clang
Assignees
Reporter edumoot
    
We compile the same source code from #83839, with different optimization level "-g -O3".  After stepping in, we got the following information.  The value of "a.f5" is not 7, but 50792199, and all the others are correct.
```
 thread #1, name = 'bug_02_O3.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555141 bug_02_O3.out`main at bug_02.c:30:5
   27  	int main(void)
   28  	{
   29  	    struct S0 a = fun_b();
-> 30  	    printf("%d\n",a.f5);
   31  	 return 0; 
   32  	}
   33  	//local_vars_info: [23, 24]
(lldb) fr v
(S0) a = (f0 = 2, f1 = -1, 0, f2 = 3, 0, f3 = 5, f4 = -6, f5 = 50792199)
(lldb) s
7
Process 3279674 stopped
* thread #1, name = 'bug_02_O3.out', stop reason = step in
    frame #0: 0x0000555555555154 bug_02_O3.out`main at bug_02.c:31:5
   28  	{
   29  	    struct S0 a = fun_b();
   30  	    printf("%d\n",a.f5);
-> 31  	    return 0; 
   32  	}
   33  	//local_vars_info: [23, 24]
   34  	
(lldb) fr v
(S0) a = (f0 = 2, f1 = -1, 0, f2 = 3, 0, f3 = 5, f4 = -6, f5 = 50792199)

```
`cat bug_02.c`
```
#include <stdio.h>
struct S0 {
   unsigned f0 : 7;
   signed f1 : 2;
   signed f2 : 29;
 unsigned f3 : 20;
   signed  f4;
   unsigned f5 : 26;
};

static int a = -1;

static int fun_a(int  p)
{ 
 return a;
}

static struct S0 fun_b(void)
{ 
    int b = 2;
    int *c = &a;
    struct S0 d = {2,-1,3,5,-6,7};
    (*c) = fun_a(b);
    return d;
}

int main(void)
{
    struct S0 a = fun_b();
    printf("%d\n",a.f5);
    return 0; 
}
```

In LLVM 18.1.2 context, Reproduce with:

```
clang -g -O3 bug_02.c -o bug_02_O3.out
lldb bug_02_O3.out
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to