Issue 91338
Summary debug informaiton issues of a pointer as a function arugment with specific optimization levels
Labels new issue
Assignees
Reporter edumoot
    
Debug information of  the function argument is not consistent with the code's behaviors:  when we pass a global pointer to a function argument ( also a pointer type), this argument would be pointing the global variable before any assignment operation on it. Specifically, the function augment, "inputPtr" is initialized to "globalIntPtr" at the moment of function calling on line 29.  However, the debug information of "* intputPtr" from line 8 to line 18, shows that it is not holding a value ("parent is NULL)". After an assignment operation on it, it has the value "1000" on line 19. 
 


Details can be seen
```lldb
(lldb) ta st a -o "fr v inputPtr *inputPtr"
Stop hook #1 added.
(lldb) b case.c:8
Breakpoint 1: where = case.out`manipulateGlobalVars + 11 at case.c:8:10, address = 0x00000000000011bb
(lldb) r
Process 1901735 launched: '/home/ad/Downloads/lldb/reproduce_bugs/case.out' (x86_64)
(int *) inputPtr = 0x0000000000000000
(int) *inputPtr = <parent is NULL>
Process 1901735 stopped
* thread #1, name = 'case.out', stop reason = breakpoint 1.1
    frame #0: 0x00005555555551bb case.out`manipulateGlobalVars(inputPtr=0x0000000000000000, inputValue=4294967295) at case.c:8:10
   5   	
   6   	static const int * manipulateGlobalVars(int * inputPtr, unsigned int inputValue)
   7 	{   
-> 8   	    int *localPtr1 = &globalInt;
   9   	    int *localPtr2 = &globalInt;
   10  	    int *localPtr3 = &globalInt;
 11  	    int *localPtr4 = &globalInt;
(lldb) s
(int *) inputPtr = 0x0000000000000000
(int) *inputPtr = <parent is NULL>
Process 1901735 stopped
* thread #1, name = 'case.out', stop reason = step in
    frame #0: 0x00005555555551c6 case.out`manipulateGlobalVars(inputPtr=0x0000000000000000, inputValue=4294967295) at case.c:9:10
   6   	static const int * manipulateGlobalVars(int * inputPtr, unsigned int inputValue)
   7   	{ 
   8   	    int *localPtr1 = &globalInt;
-> 9   	    int *localPtr2 = &globalInt;
   10  	    int *localPtr3 = &globalInt;
   11  	 int *localPtr4 = &globalInt;
   12  	    int *localPtr5 = &globalInt;
```

```
(lldb) s
(int *) inputPtr = 0x0000000000000000
(int) *inputPtr = <parent is NULL>
Process 1901735 stopped
* thread #1, name = 'case.out', stop reason = step in
    frame #0: 0x00005555555551ea case.out`manipulateGlobalVars(inputPtr=0x0000000000000000, inputValue=4294967295) at case.c:18:14
   15  	    int *localPtr8 = &globalInt;
   16  	    int *localPtr9 = &globalInt;
   17  	    int *localPtr10 = &globalInt;
-> 18  	    inputPtr = localPtr1;
   19  	 assert (inputPtr == &globalInt);
   20  	    ++globalCounter;
   21 	    return localPtr8;
(lldb) s
(int *) inputPtr = 0x0000555555558038
(int) *inputPtr = 1000
Process 1901735 stopped
* thread #1, name = 'case.out', stop reason = step in
    frame #0: 0x00005555555551f0 case.out`manipulateGlobalVars(inputPtr=0x0000555555558038, inputValue=4294967295) at case.c:19:5
   16  	    int *localPtr9 = &globalInt;
   17  	    int *localPtr10 = &globalInt;
   18  	 inputPtr = localPtr1;
-> 19  	    assert (inputPtr == &globalInt);
 20  	    ++globalCounter;
   21  	    return localPtr8;
   22 	}

```
GDB  produces the same result.
```
8	    int *localPtr1 = &globalInt;
1: inputPtr = (int *) 0x8
2: *inputPtr = <error: Cannot access memory at address 0x8>
(gdb) s
9	    int *localPtr2 = &globalInt;
1: inputPtr = (int *) 0x8
2: *inputPtr = <error: Cannot access memory at address 0x8>
(gdb) s
10	    int *localPtr3 = &globalInt;
1: inputPtr = (int *) 0x8
2: *inputPtr = <error: Cannot access memory at address 0x8>



(gdb) s
19	 assert (inputPtr == &globalInt);
1: inputPtr = (int *) 0x555555558038 <globalInt>
2: *inputPtr = 1000

```


`cat case.c`

``` c source code
#include <assert.h>
static int globalInt = 1000;
static int *globalIntPtr = &globalInt;
static unsigned int globalCounter = 5000U;

static const int * manipulateGlobalVars(int * inputPtr, unsigned int inputValue)
{   
 int *localPtr1 = &globalInt;
    int *localPtr2 = &globalInt;
    int *localPtr3 = &globalInt;
    int *localPtr4 = &globalInt;
    int *localPtr5 = &globalInt;
    int *localPtr6 = &globalInt;
    int *localPtr7 = &globalInt;
    int *localPtr8 = &globalInt;
    int *localPtr9 = &globalInt;
    int *localPtr10 = &globalInt;
    inputPtr = localPtr1;
    assert (inputPtr == &globalInt);
 ++globalCounter;
    return localPtr8;
}

static unsigned int manipulateGlobalVarsWrapper(void)
{ 
    int localInt = (-1);
 int **nullPtr = (void*)0;
    int **localIntPtr = &globalIntPtr;
 (*localIntPtr) = manipulateGlobalVars(globalIntPtr, localInt);
    return globalInt;
}

int main (void)
{
 manipulateGlobalVarsWrapper();
    return 0;
}
```
The compilation pipelines of llvm (18.1.2 and 17.0.6) are as follows:
```compiling pipelines
clang -g -O0 case.c -Xclang -disable-O0-optnone -emit-llvm -c -o case.bc
opt -passes='default<O0>' case.bc  -o case.opt.bc
llc -O1  --relocation-model=pic case.opt.bc -o case.s
clang  case.s -o case.out
```

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

Reply via email to