Peng Yu via llvm-dev
2019-Jan-22 19:30 UTC
[llvm-dev] Must string literals be declared as a global variable in LLVM IR?
Hi,
#include <stdio.h>
int main(int argc, char *argv[]) {
puts("Hello World!");
return 0;
}
The above C code is converted to the following IR code. The string
literal "Hello World!" is defined as an unnamed global constant.
Does the IR language support the declaration of local values to store
the string literal? I don't this is supported as I am reading the
manual. But I would like to double check. Thanks.
@.str = private unnamed_addr constant [13 x i8] c"Hello World!\00",
align 1
; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main(i32, i8**) #0 !dbg !7 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
call void @llvm.dbg.declare(metadata i32* %4, metadata !14, metadata
!DIExpression()), !dbg !15
store i8** %1, i8*** %5, align 8
call void @llvm.dbg.declare(metadata i8*** %5, metadata !16,
metadata !DIExpression()), !dbg !17
%6 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x
i8]* @.str, i32 0, i32 0)), !dbg !18
ret i32 0, !dbg !19
}
--
Regards,
Peng
Eli Friedman via llvm-dev
2019-Jan-22 20:00 UTC
[llvm-dev] Must string literals be declared as a global variable in LLVM IR?
On 1/22/2019 11:30 AM, Peng Yu via llvm-dev wrote:> Hi, > > > #include <stdio.h> > > int main(int argc, char *argv[]) { > puts("Hello World!"); > return 0; > } > > The above C code is converted to the following IR code. The string > literal "Hello World!" is defined as an unnamed global constant. > > Does the IR language support the declaration of local values to store > the string literal? I don't this is supported as I am reading the > manual. But I would like to double check. Thanks.If you want a pointer to a value, it has to be located somewhere in memory. There are basically three places memory can be allocated in a program: on the stack (alloca), on the heap (malloc), or in program memory (a global variable/constant). -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Peng Yu via llvm-dev
2019-Jan-22 20:48 UTC
[llvm-dev] Must string literals be declared as a global variable in LLVM IR?
> If you want a pointer to a value, it has to be located somewhere in > memory. There are basically three places memory can be allocated in a > program: on the stack (alloca),Even I can alloca a chuck of memory, there is not a way to put the string constant to it? Sounds likely there is not way to avoid the initialization of the global variables. Is it?> on the heap (malloc), or in program > memory (a global variable/constant).-- Regards, Peng
Reasonably Related Threads
- Information Loss of Array Type in Function Interface in IR Generated by Clang
- Information Loss of Array Type in Function Interface in IR Generated by Clang
- What does "preds" mean in a .ll file?
- DIGlobalVariableExpression doc in langref
- LSR breaks debug info