Skip to content

Commit 9eb3fd8

Browse files
committed
---
yaml --- r: 42393 b: refs/heads/master c: dd7a81d h: refs/heads/master i: 42391: 560f9e9 v: v3
1 parent 9cc2a0c commit 9eb3fd8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: dd41f044da5f8f20798122d2a138ea614600c16e
2+
refs/heads/master: dd7a81d025802021d49e9a69016a890f421d1833
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/librustc/middle/trans/machine.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,16 @@ pub fn llbitsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
126126
}
127127
}
128128

129-
// Returns the "default" size of t, which is calculated by casting null to a
130-
// *T and then doing gep(1) on it and measuring the result. Really, look in
131-
// the LLVM sources. It does that. So this is likely similar to the ABI size
132-
// (i.e. including alignment-padding), but goodness knows which alignment it
133-
// winds up using. Probably the ABI one? Not recommended.
129+
/// Returns the size of the type as an LLVM constant integer value.
134130
pub fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
135-
unsafe {
136-
return llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t),
137-
cx.int_type,
138-
False);
139-
}
131+
// Once upon a time, this called LLVMSizeOf, which does a
132+
// getelementptr(1) on a null pointer and casts to an int, in
133+
// order to obtain the type size as a value without requiring the
134+
// target data layout. But we have the target data layout, so
135+
// there's no need for that contrivance. The instruction
136+
// selection DAG generator would flatten that GEP(1) node into a
137+
// constant of the type's alloc size, so let's save it some work.
138+
return C_uint(cx, llsize_of_alloc(cx, t));
140139
}
141140

142141
// Returns the "default" size of t (see above), or 1 if the size would

0 commit comments

Comments
 (0)