华为计算微信公众号
华为计算微博
华为计算今日头条
对于如下代码,在gcc -O0/1/2/3/s 都输出0, 在bisheng/clang -O0/1 也输出0, 但bisheng/clang -O2/3/s 输出50.
#include <stdio.h> #include <stdint.h> uint8_t k[6][3]; int a(char b, int c) { char d[] = {2, 4, 0, b, 77}; char *e = d, *g = &e[c], *h = d; int f = 0; while (h < g) { f++; while (*h++ & 128) ; } return f; } uint8_t l(); static int64_t m() { if (l()) { uint8_t *n = &k[1][1]; *n = 50; } return 0; } uint8_t l() { return a(-59, 5) - 4; } int main() { int i, j; for (i = 0; i < 6; i++) for (j = 0; j < 3; j++) k[i][j] = 0; m(); printf("%d\n", k[1][1]); }
编译如下:
$ gcc-13 test.c && ./a.out 0 $ bisheng/clang -O0 test.c && ./a.out 0 $ bisheng/clang -O1 test.c && ./a.out 0 $ bisheng/clang -O2 test.c && ./a.out 50 $ bisheng/clang -O3 test.c && ./a.out 50 $ bisheng/clang -Os test.c && ./a.out 50
编译器版本如下:
$ bisheng/clang --version BiSheng Enterprise 4.0.0.B014 clang version 17.0.6 (0ac87bc45325) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /root/compilers/BiShengCompiler-4.0.0-aarch64-linux/bin
我要发帖子
对于如下代码,在gcc -O0/1/2/3/s 都输出0, 在bisheng/clang -O0/1 也输出0, 但bisheng/clang -O2/3/s 输出50.
#include <stdio.h> #include <stdint.h> uint8_t k[6][3]; int a(char b, int c) { char d[] = {2, 4, 0, b, 77}; char *e = d, *g = &e[c], *h = d; int f = 0; while (h < g) { f++; while (*h++ & 128) ; } return f; } uint8_t l(); static int64_t m() { if (l()) { uint8_t *n = &k[1][1]; *n = 50; } return 0; } uint8_t l() { return a(-59, 5) - 4; } int main() { int i, j; for (i = 0; i < 6; i++) for (j = 0; j < 3; j++) k[i][j] = 0; m(); printf("%d\n", k[1][1]); }编译如下:
编译器版本如下: