Issue |
148955
|
Summary |
[clang] Constant "(a && 0)" not folded at -O0
|
Labels |
clang
|
Assignees |
|
Reporter |
pbo-linaro
|
While working on QEMU, we recently exposed a missed constant folding with ``clang -O0``.
Given this code:
```
$ cat main.c
extern int f(void);
int main(int argc) {
if (argc && 0)
f();
}
$ clang -O0 main.c
/usr/bin/ld: /tmp/main-19bcf0.o: in function `main':
main.c:(.text+0x21): undefined reference to `f'
```
Since ``argc && 0`` is always false, it could be expected (though not required by the standard) that branch is eliminated and thus, `f` should not be referenced. Some code on QEMU expect dead code elimination to happen, to not cross reference some symbols.
When changing condition to ``(0 && argc)``, the branch is removed as expected.
Original discussion on QEMU side: https://lore.kernel.org/qemu-devel/95b00393-bdd2-4db3-ac39-02a09f83b...@linaro.org/
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs