79806986

Date: 2025-11-02 07:25:52
Score: 0.5
Natty:
Report link

@ssd

In fact, all C compilers tend to somewhat ignore restrict. When do_another_thing and entry are compiled in the same source file, the compiler will perform its own analysis and then assume that xxx might be continuously modified.

int xxx_create(int *p_xxx);
int xxx_do_something(int xxx);

void do_another_thing(int* restrict xxx) {
    xxx_do_something(*xxx);
    xxx_do_something(*xxx);
    xxx_do_something(*xxx);
}

int entry() {
    int xxx;

    xxx_create(&xxx);
    
    do_another_thing(&xxx);
    
    return 0;
}
        .file   "example.c"
# GNU C23 (Compiler-Explorer-Build-gcc--binutils-2.44) version 15.2.0 (x86_64-linux-gnu)
#       compiled by GNU C version 11.4.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP

# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mtune=generic -march=x86-64 -g -g0 -Ofast -fno-asynchronous-unwind-tables
        .text
        .p2align 4
        .globl  do_another_thing
        .type   do_another_thing, @function
do_another_thing:
        pushq   %rbx  #
# /app/example.c:4: void do_another_thing(int* restrict xxx) {
        movq    %rdi, %rbx      # xxx, xxx
# /app/example.c:5:     xxx_do_something(*xxx);
        movl    (%rdi), %edi    # *xxx_5(D), *xxx_5(D)
        call    xxx_do_something        #
# /app/example.c:6:     xxx_do_something(*xxx);
        movl    (%rbx), %edi    # *xxx_5(D), *xxx_5(D)
        call    xxx_do_something        #
# /app/example.c:7:     xxx_do_something(*xxx);
        movl    (%rbx), %edi    # *xxx_5(D), *xxx_5(D)
# /app/example.c:8: }
        popq    %rbx    #
# /app/example.c:7:     xxx_do_something(*xxx);
        jmp     xxx_do_something  #
        .size   do_another_thing, .-do_another_thing
        .p2align 4
        .globl  entry
        .type   entry, @function
entry:
        subq    $24, %rsp       #,
# /app/example.c:13:     xxx_create(&xxx);
        leaq    12(%rsp), %rdi  #, tmp102
        call    xxx_create      #
# /app/example.c:5:     xxx_do_something(*xxx);
        movl    12(%rsp), %edi  # xxx,
        call    xxx_do_something        #
# /app/example.c:6:     xxx_do_something(*xxx);
        movl    12(%rsp), %edi  # xxx,
        call    xxx_do_something        #
# /app/example.c:7:     xxx_do_something(*xxx);
        movl    12(%rsp), %edi  # xxx,
        call    xxx_do_something        #
# /app/example.c:18: }
        xorl    %eax, %eax      #
        addq    $24, %rsp       #,
        ret     
        .size   entry, .-entry
        .ident  "GCC: (Compiler-Explorer-Build-gcc--binutils-2.44) 15.2.0"
        .section        .note.GNU-stack,"",@progbits
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @ssd
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Moi5t