diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-11-22 07:14:04 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-11-22 07:14:04 +0800 |
commit | 74d40501cd27484f26cbbb920d441faec9007242 (patch) | |
tree | ead9ce94d7be0a92cfc815417ecc1059e836442d /src | |
parent | 33bf75d5b26248950757f3b580337d6db271b8b1 (diff) | |
download | mrust-74d40501cd27484f26cbbb920d441faec9007242.tar.gz |
Target - Fix struct size calculations (align overall size)
Diffstat (limited to 'src')
-rw-r--r-- | src/trans/target.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/trans/target.cpp b/src/trans/target.cpp index d653a086..52a06909 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -194,6 +194,7 @@ namespace { StructRepr rv; size_t cur_ofs = 0; + size_t max_align = 1; for(auto& e : ents) { // Increase offset to fit alignment @@ -205,10 +206,19 @@ namespace { cur_ofs ++; } } + max_align = ::std::max(max_align, e.align); rv.ents.push_back(mv$(e)); cur_ofs += e.size; } + if( !packed ) + { + while( cur_ofs % max_align != 0 ) + { + rv.ents.push_back({ ~0u, 1, 1, ::HIR::TypeRef( ::HIR::CoreType::U8 ) }); + cur_ofs ++; + } + } return box$(rv); } } |