[LLVMdev] translating Objective C to C

Cristiano Calcagno ccris at doc.ic.ac.uk
Fri Jun 6 00:35:11 PDT 2008

  I am thinking of integrating llvm's front end and intermediate  
language with program analysis tools I am developing with my  
colleagues (we look for memory errors and leaks, integrity of data  
structures, etc. -- for details see http://spaceinvader-eastlondonmassive.blogspot.com/) 
My initial baby experiment was simply translating C++ to C using llvm,  
followed by analysis of the C code (our tools only support C at the  
When trying to do the same with Objective C, I got C code which cannot  
be compiled, because the same symbol gets declared several times in  
the C source.

  >llvm-gcc -emit-llvm helloworld.m -c -o main.bc
  >llc -march=c main.bc -o main.c
  >gcc -c main.c
  main.c:321: error: redefinition of ‘L_OBJC_METH_VAR_NAME_0’
  main.c:319: error: previous definition of ‘L_OBJC_METH_VAR_NAME_0’  
was here

The generated code in main.c includes for example:

static unsigned char L_OBJC_METH_VAR_NAME_0[9] = "sayHello";
static unsigned char L_OBJC_METH_VAR_TYPE_0[7] = "v8 at 0:4";
static unsigned char L_OBJC_METH_VAR_NAME_0[9] = "sayHello";

This was last week on a macbook, which I would expect is the ideal  
platform to try this.
Has anyone tried to do the same? (I can provide the specific source,  
but I don't think it matters).

Thank you for the great project.

More information about the llvm-dev mailing list