[PATCH] D79314: PR45733 : global weak symbol are excluded from the optimization .
Umesh Kalappa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 12 00:30:17 PDT 2020
umesh.kalappa0 added a comment.
In D79314#2029834 <https://reviews.llvm.org/D79314#2029834>, @efriedma wrote:
> You still haven't explained why you think ConstantFolding is wrong, given the definition of weak_odr in LangRef.
@efriedma ,consider the below case ,
bft at bft-OptiPlex-5050:~$ cat weak.c
#pragma weak x
const int x = 5;
int foo ()
{ return x; }
bft at bft-OptiPlex-5050:~$ cat main.c
int x =20;
int foo();
main()
{
printf("weak linkage %d\n",foo());
}
bft at bft-OptiPlex-5050:~$ clang main.c weak.c
bft at bft-OptiPlex-5050:~$ ./a.out
weak linkage 20
bft at bft-OptiPlex-5050:~$ clang -O2 main.c weak.c
bft at bft-OptiPlex-5050:~$ ./a.out
weak linkage 5
with O2 <https://reviews.llvm.org/owners/package/2/> earlyCSE constant fold the variable "x" to constantl_5 (which is incorrect ) .so below fix was recommended to prevent the same.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79314/new/
https://reviews.llvm.org/D79314
More information about the llvm-commits
mailing list