Problem using march=c

Hello everyone,

I've been trying to generate a C file using the llc tool, but I'm
having a problem. I'm using a single Hello World program in C, and
executing the following passes:

clang -emit-llvm -c -o hello.bc hello.c # getting the bit code of hello.c
llc -march=c hello.bc # generating the
hello.cbe.c file using the llvm C backend

So far, nothing weird happened. The problem occurs once I try to
compile the hello.cbe.c: gcc, and even clang, show me some warning and
error messages.
Cheking in hello.cbe.c, I could see that the problem was related with
the structs declarations and initialization. There, they appears to be
something like

        /* Global Variable Declarations */
        static _OC_str { unsigned char array[13]; };

        /* Global Variable Definitions and Initialization */
        static _OC_str { unsigned char array[13]; } = { "Hello World\n" };

when they should be like

        /* Global Variable Declarations */
        static struct type_OC_str { unsigned char array[13]; };

        /* Global Variable Definitions and Initialization */
        static struct type_OC_str _OC_str = { "Hello World\n" };

It is a known problem, or am I doing something wrong?

Thks in advance,

Hello

It is a known problem, or am I doing something wrong?

C backend is known to be buggy.

Hi Cristianno,

This problem has been around for a while, ourselves we solve it with the following patches:

https://hpcforge.org/scm/viewvc.php/trunk/patches/llvm.gpu.patch?root=kernelgen&view=markup

https://hpcforge.org/scm/viewvc.php/trunk/patches/llvm.patch?revision=591&root=kernelgen&view=markup

Please feel free to apply them, they should work for you even with the latest llvm 3.1. Also please feel free to ping me in case of any troubles.

  • D.

Hello again,

Thanks for the responses =)

Dmitry, I have two points to comment:
- First, I applied these two patches, and the .cbe.c file came out ok,
except for one little thing -- the global variable was created with
both modifiers: static and extern. Then, I just added a single guard
to prevent this to happen (in a case of a variable having local
linkage, the "extern" part was not printed to file).
- Second, I created the patch appended in this email, but instead of
representing only the "guard-adding" part, this patch is a union of
this change, and the others two patches you sent to me.

Thanks again,

CBackend.patch (19.7 KB)

Hi Cristianno,

Great to know it works for you! Btw it would be very nice if someone could help cleaning these fixes from CUDA/OpenCL stuff and contribute patch to trunk, finally, with some tests.

the global variable was created with both modifiers: static and extern.

Oh, right, this is wrong in general, was there just to unify behavior with the cudafe source preprocessor, which does the same thing, since on GPU global variables could not be shared between compilation units.

  • D.

2012/3/5 Cristianno Martins <cristiannomartins@gmail.com>