[llvm-dev] Must string literals be declared as a global variable in LLVM IR?

Eli Friedman via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 22 12:00:01 PST 2019

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).


Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

More information about the llvm-dev mailing list