Skip to content

Mistake eliminating function call #142086

Closed as not planned
Closed as not planned
@wzssyqa

Description

@wzssyqa
#include <malloc.h>
#include <stdint.h>
#include <string.h>

struct xx {
        int *base;
        int *r1;
        int *r2;
        int *r3;
};

void f(struct xx *s) {
        int    prealloc_idx = 0;
        int64_t prealloc_size = 0;
        uint8_t **preallocs[64];
        {
                s->r1 = (void*)(intptr_t)prealloc_size;
                preallocs[prealloc_idx++] = (uint8_t**)&(s->r1);
                prealloc_size += sizeof(int) * 128;
        }
        {
                s->r2 = (void*)(intptr_t)prealloc_size;
                preallocs[prealloc_idx++] = (uint8_t**)&(s->r3);
                prealloc_size += sizeof(int) * 128;
        }
        {
                s->r3 = (void*)(intptr_t)prealloc_size;
                preallocs[prealloc_idx++] = (uint8_t**)&(s->r3);
                prealloc_size += sizeof(int) * 128;
        }
        s->base = malloc(prealloc_size);
        while( prealloc_idx-- )
                *preallocs[prealloc_idx] = (uint8_t*)((intptr_t)(*preallocs[prealloc_idx]) + (intptr_t)s->base);

        memset(s->r1, -2, sizeof(int) * 128);
        memset(s->r2, -2, sizeof(int) * 128);
        memset(s->r3, -2, sizeof(int) * 128);
}

In this code, memset are eliminated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions