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

Peng Yu via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 22 11:30:43 PST 2019


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


More information about the llvm-dev mailing list