I came across this behavior irregularity in LLVM for ARM backend (-target arm-linux-gnueabi) with the constant promotion optimization in arm (-arm-promote-constant=true).
For the attached source files compiling with the following:
clang++ -target arm-linux-gnueabi A.cpp B.cpp –o a.out
The addresses returned from bar() and foo() are not the same (string literals live in different memory locations) however, when we turn off the constant pool optimization
clang-arm-x++ -Ofast -mllvm -arm-promote-constant=false A.cpp B.cpp -o test_case.exe –o a.out
we are getting the same addresses for string literals.
Looking into the ll files , the strings are created as “private unnamed_addr constant” so the constant pool optimization pass is promoting them to constant pools and causing them to have different addresses, which seems fine.
Is this behavior in line with the C++ standard for strings in extern inline functions? If not, what should be the correct linkage type emitted for this constant? Is this a potential clang bug?
A.cpp (256 Bytes)
B.cpp (99 Bytes)
B.ll (1.26 KB)
A.ll (6.32 KB)