Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected top-level entity

Tags:

llvm

How did you managed to pass through expected top-level entity error while executing lli in the llvm framework?

like image 916
speedyxvs Avatar asked Jan 30 '13 12:01

speedyxvs


2 Answers

This error usually means that you copy-pasted part of some IR code which doesn't count as a top level entity. In other words, it's not a function, not a type, not a global variable, etc. The same error can happen in C, just for comparison:

x = 8;

Is not valid contents for a C file, because the assignment statement isn't a valid top level entity. To make it valid you put it in a function:

void foo() {
  x = 8;   /* assuming x is global and visible here */
}

The same error happens in LLVM IR.

like image 189
Eli Bendersky Avatar answered Oct 10 '22 14:10

Eli Bendersky


My Issue: The .ll file format was "UTF-8 with BOM" instead of "UTF-8 without BOM".

Fix: With notepad++, in the encoding menu, select the "UTF-8 without BOM", then save.

Quick setup: (For llvm 3.4.0 .ll files on windows)

advanced text editor from https://notepad-plus-plus.org/

llvm binaries from https://github.com/CRogers/LLVM-Windows-Binaries

hello.ll as "UTF-8 without BOM" (This code is in llvm 3.4.0 format):

@msg = internal constant [13 x i8] c"Hello World!\00"
declare i32 @puts(i8*)
define i32 @main() {
    call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @msg, i32 0, i32 0))
    ret i32 0
}

In command prompt:

lli hello.ll

Quick setup: (For llvm 3.8.0 .ll files on windows)

advanced text editor from https://notepad-plus-plus.org/

clang binaries from: http://llvm.org/releases/download.html#3.8.0

hello.ll as "UTF-8 without BOM" (This code is in llvm 3.8.0 format):

@msg = internal constant [13 x i8] c"Hello World!\00"
declare i32 @puts(i8*)
define i32 @main() {
    call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @msg, i32 0, i32 0))
    ret i32 0
}

In command prompt:

clang hello.ll -o hello.exe
hello.exe

Errors about char16_t, u16String, etc means clang needs: -fms-compatibility-version=19

like image 38
Mi G Avatar answered Oct 10 '22 15:10

Mi G