summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-02-04 18:36:48 +0800
committerJohn Hodge <tpg@mutabah.net>2018-02-04 18:36:48 +0800
commit143135bdc9f14c3318384543e110bcfcf1e93718 (patch)
tree5c475effdb06374183480bfdc438bc60077584c2
parent8fb6df4340c186fbc391b18dc026cd868f74b6ac (diff)
downloadmrust-143135bdc9f14c3318384543e110bcfcf1e93718.tar.gz
Target - Fix incorrect array size calculation
-rw-r--r--src/trans/target.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/trans/target.cpp b/src/trans/target.cpp
index d1a5cabe..09fc45b7 100644
--- a/src/trans/target.cpp
+++ b/src/trans/target.cpp
@@ -276,6 +276,7 @@ const StructRepr* Target_GetStructRepr(const Span& sp, const StaticTraitResolve&
bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size, size_t& out_align)
{
+ TRACE_FUNCTION_FR(ty, "size=" << out_size << ", align=" << out_align);
TU_MATCHA( (ty.m_data), (te),
(Infer,
BUG(sp, "sizeof on _ type");
@@ -362,20 +363,19 @@ bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve,
BUG(sp, "sizeof on an erased type - shouldn't exist");
),
(Array,
- size_t size;
- if( !Target_GetSizeAndAlignOf(sp, resolve, *te.inner, size,out_align) )
+ if( !Target_GetSizeAndAlignOf(sp, resolve, *te.inner, out_size,out_align) )
return false;
- if( size == SIZE_MAX )
+ if( out_size == SIZE_MAX )
BUG(sp, "Unsized type in array - " << ty);
- if( te.size_val == 0 )
+ if( te.size_val == 0 || out_size == 0 )
{
- size = 0;
+ out_size = 0;
}
else
{
- if( SIZE_MAX / te.size_val <= size )
+ if( SIZE_MAX / te.size_val <= out_size )
BUG(sp, "Integer overflow calculating array size");
- size *= te.size_val;
+ out_size *= te.size_val;
}
return true;
),