Problems with "module asm"

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@ubuntu:/tmp$ cat test.c
module asm ("hello");
module asm ("world");
int main (void) {
}

i00202@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@ubuntu:/tmp$ cat test.ll
; ModuleID = 'test.c'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu"
@"\01world" = common global i32 0, align 4 ; <i32*> [#uses=0]

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

module asm ("hello") is misssing.

That declares a variable of type int whose name in the assembly is "
blah "; not what you want. The correct C syntax is just the
following:
asm(" blah ");

-Eli

Hello

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

I think you confused LLVM IR with C/C++ since you're citing LLVM
langref document but then due to some unknown to me reason tries to
use LLVM IR syntax in C source.

Anton Korobeynikov wrote:

Hello

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

I think you confused LLVM IR with C/C++ since you're citing LLVM
langref document but then due to some unknown to me reason tries to
use LLVM IR syntax in C source.

You are right. What's the C equivalent? When does clang generates module asm?

- Sanjiv

Sanjiv Gupta wrote:

Anton Korobeynikov wrote:
  

Hello

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

I think you confused LLVM IR with C/C++ since you're citing LLVM
langref document but then due to some unknown to me reason tries to
use LLVM IR syntax in C source.

You are right. What's the C equivalent? When does clang generates module asm?

- Sanjiv
  

Please ignore that. Eli had already answered that in one of the other emails.