https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108915

            Bug ID: 108915
           Summary: invalid pointer access preserved in optimized code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hiraditya at msn dot com
  Target Milestone: ---

Testcase has been reduced from u-boot's linker-list macro:
https://github.com/u-boot/u-boot/blob/master/include/linker_lists.h#L127


#include<stdio.h>

char* bar() {
    static char start_bar[0] __attribute__((aligned(16)))
       __attribute__((unused))
       __attribute__((section("__u_boot_list_2_1")));
    char *p = (char *)start_bar;
    for (int i = p[0]; i < p[9]; i++)
        printf("asdfasd");
    return 0;
}



$ gcc -O3 -fno-unroll-loops -S -o -

.LC0:
        .string "asdfasd"
bar:
        push    rbx
        movsx   eax, BYTE PTR start_bar.1[rip+9]
        movsx   ebx, BYTE PTR start_bar.1[rip]
        cmp     ebx, eax
        jge     .L2
.L3:
        mov     edi, OFFSET FLAT:.LC0
        xor     eax, eax
        add     ebx, 1
        call    printf
        movsx   eax, BYTE PTR start_bar.1[rip+9]
        cmp     eax, ebx
        jg      .L3
.L2:
        xor     eax, eax
        pop     rbx
        ret

-----------------------------------------------------
$ clang -O3 -fno-unroll-loops -S -o -

bar:                                    # @bar
        xor     eax, eax
        ret

Reply via email to