[LLVMdev] Problems with "module asm"

Sanjiv Gupta sanjiv.gupta at microchip.com
Mon Jun 29 22:14:07 PDT 2009

This is what the document says:

Module-Level Inline Assembly

Modules may contain "module-level inline asm" blocks, which corresponds 
to the GCC "file scope inline asm" blocks. These blocks are internally 
concatenated by LLVM and treated as a single unit, but may be separated 
in the .ll file if desired. The syntax is very simple:

module asm "inline asm code goes here"
module asm "more can go here"

The strings can contain any character by escaping non-printable 
characters. The escape sequence used is simply "\xx" where "xx" is the 
two digit hex code for the number.

The inline asm code is simply printed to the machine code .s file when 
assembly code is generated.

Here are the problems:

1.  clang-cc needs parentheses or else gives errors. So the actual 
syntax is
     module asm (" blah ");

2. clang-cc gives warnings like
i00202 at ubuntu:/tmp$ cat test.c
module asm ("hello");
module asm ("world");
int main (void) {

i00202 at ubuntu:/tmp$ clang-cc -emit-llvm test.c
test.c:1:1: warning: type specifier missing, defaults to 'int'
module asm ("hello");
test.c:2:1: warning: type specifier missing, defaults to 'int'
module asm ("world");
2 diagnostics generated.

3. The blocks are NOT being concatenated.  Below is the generated .ll file.
i00202 at ubuntu:/tmp$ cat test.ll
; ModuleID = 'test.c'
target datalayout = 
target triple = "i386-pc-linux-gnu"
@"\01world" = common global i32 0, align 4        ; <i32*> [#uses=0]

define i32 @main() nounwind {
    %retval = alloca i32        ; <i32*> [#uses=1]
    %0 = load i32* %retval        ; <i32> [#uses=1]
    ret i32 %0

module asm ("hello") is misssing.

More information about the llvm-dev mailing list