[llvm-dev] [ARM] [C++ standard] Correct linkage type for string literals in extern inline functions

Sameer AbuAsal via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 21 17:48:28 PDT 2017


Hi, 

 

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?

 

Thank you,

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/5a942354/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.cpp
Type: application/octet-stream
Size: 256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/5a942354/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B.cpp
Type: application/octet-stream
Size: 99 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/5a942354/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B.ll
Type: application/octet-stream
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/5a942354/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.ll
Type: application/octet-stream
Size: 6474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/5a942354/attachment-0007.obj>


More information about the llvm-dev mailing list