Issue 114185
Summary Incorrect assembly code generated with -Os
Labels new issue
Assignees
Reporter mushenoy
    For the below sample source file -  the assembly code generated is incorrect.

Sample.c:
```
struct sample {
    struct sample *next;
    char a;
};

char function (char);
void test(void);

void* test_function (const struct sample *c)
{
    char type;
    if (c) {
        type = c->a;
 test();
   }
   function(type);
   return (void *)0;
} 
```

Compilation command:

```
clang --target=aarch64-linux-gnu -save-temps -c sample.c -o sample.o -Os

```

In the assembly:
- No conditional branch is generated to check if `c` is non-null.
- test function call is done unconditionally


Assembly code:

```
test_function:
 stp     x29, x30, [sp, #-32]!
        str     x19, [sp, #16]
 mov     x29, sp
        ldrb    w19, [x0, #8]
        bl      test
 mov     w0, w19
        bl      function
        mov     x0, xzr
        ldr     x19, [sp, #16]
        ldp     x29, x30, [sp], #32
        ret
```

x86_64:
```
test_function:
 push    rbx
        movsx   ebx, byte ptr [rdi + 8]
        call test@PLT
        mov     edi, ebx
        call    function@PLT
 xor     eax, eax
        pop     rbx
        ret
 ```
 
 Observations:
 - The issue is observed when -Os is used
 - Code gets generated correctly when `type` variable is initialized with some value.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to