如何防止clang / llvm将局部变量编译为全局变量?

时间:2018-05-02 03:38:26

标签: c gcc clang llvm

我有一个C代码:

int64_t sample_max(int64_t *beg, int64_t len) {
    if (len == 0) {
        return 0;
    }
    int64_t max = 0x8000000000000000;
    int64_t *end = beg + len;
    while (beg < end) {
        if (*beg > max) {
            max = *beg;
        }
        beg++;
    }
    return max;
}

并通过clang编译:

clang -S -target x86_64-unknown-none -masm=intel -mno-red-zone -mstackrealign -mllvm -inline-threshold=1000 -fno-asynchronous-unwind-tables -fno-exceptions -fno-rtti -O3 -fno-builtin -ffast-math -mavx2 lib/sample.c -o lib/sample_avx2.s

我发现clang / llvm编译局部变量&#34; max = 0x8000000000000000&#34;全球:

vpbroadcastq    ymm0, qword ptr [rip + .LCPI1_0]
    vmovdqa ymm3, ymm0
    vmovdqa ymm2, ymm0
    vmovdqa ymm1, ymm0

....

.LCPI1_0:
    .quad   -9223372036854775808    # 0x8000000000000000
    .section    .rodata,"a",@progbits
    .align  32

如何防止clang / llvm将局部变量编译为全局变量? 我们可以将0x8000000000000000编译为立即值吗?

感谢。

0 个答案:

没有答案