LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1242 - llvm-gcc emits llvm assembly with incomplete target data layout
Summary: llvm-gcc emits llvm assembly with incomplete target data layout
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-gcc (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2007-03-05 19:02 PST by Reid Spencer
Modified: 2010-02-22 12:55 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
A simple program that produces the bug. (1.00 KB, text/plain)
2007-03-05 19:06 PST, Reid Spencer
Details
Equivalent llvm assembly for struct-size.c (3.08 KB, text/plain)
2007-03-05 19:07 PST, Reid Spencer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Spencer 2007-03-05 19:02:19 PST
When emitting llvm code (-emit-llvm), llvm-gcc generates a Target Data Layout of
"e-p:32:32" for x86-pc-linux-gnu. This is insufficient for some programs as the
defaults will use f64:64:64 whereas the correct alignment is f64:32:64. This
causes a problem in accessing fields of structures that use double/long long.
Comment 1 Reid Spencer 2007-03-05 19:06:46 PST
Created attachment 696 [details]
A simple program that produces the bug.

This program is extracted (manually) from llvm-test/MultiSource/Olden/bh. It
simply allocates and initializes a structure containing several fields. When
the last field is initialized this causes LLI to corrupt memory because the
StructureLayout returned an offset of 136 for the last field while llvm-gcc
generated a malloc call for only 132 bytes. Subsequent operations result in a
glibc malloc error. 

This doesn't happen in llc or jit because they update the target data for the
specific target for which code is being generated.
Comment 2 Reid Spencer 2007-03-05 19:07:58 PST
Created attachment 697 [details]
Equivalent llvm assembly for struct-size.c

This is generated by llvm-gcc -S -emit-llvm struct-size.c -o ss.ll
Comment 3 Chris Lattner 2007-03-05 19:09:44 PST
Fixed, patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070305/045573.html