[LLVMdev] llc c backend can produce code that doesn't compile on gcc 4.x

Gordon Henriksen gordonhenriksen at mac.com
Mon Jan 15 22:53:29 PST 2007


On 2007-01-15, at 11:48, Chris Lattner wrote:

> On Mon, 15 Jan 2007, Nick Lewycky wrote:
>
>> The structure contents are defined right afterwards, but I assume  
>> that the typedefs are used when emitting the structure contents?  
>> We may have to put fully defined structures first and typedefs  
>> second.
>
> Looks like it.  It sounds like the CBE should build an ordering of  
> types, based on their nesting properties, then emit them in nesting  
> order. Because all recursive types have to go through a pointer in  
> C, we should get a dag of types, which is easy to emit.

A DAG traversal is already performed, but only for struct types. It  
is implemented in CWriter::printContainedStructs (lib/Target/CBackend/ 
CBackend.cpp:1722).

The bug is in the calling function, printModuleTypes, which prints  
typedefs for all named types before performing the dependency- 
sensitive traversal. For array typedefs, this ordering is incorrect;  
the element type must be defined first. But consider something like  
[2 x { [2 x {int}] }]; these two stages must be interleaved.

The simplest solution is to avoid typedefs for array types. With  
names of array types removed from the symbol table, llc will simply  
output (for instance) 'l_structtype_s[3]' instead of the equivalent  
'l_fixarray_array3'.

A more ambitious fix would be to merge the "typedef" and "structure  
contents" loops into a single, substantially more complex dependency- 
ordered traversal. This would preserve type names from the bytecode  
file—but to what end?

Here's the patch and test:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of- 
Mon-20070115/042760.html

A workaround for this bug was to avoid naming array types in .ll files.

— Gordon





More information about the llvm-dev mailing list