From a54430ea2dc7d39670e0451a04d3b9f349ae8072 Mon Sep 17 00:00:00 2001 From: sleepyqt Date: Wed, 10 Jan 2018 01:02:09 +0300 Subject: [PATCH] Fix struct packing for VCC. (#7049) "#pragma pack(1)" sets current alligment without pushing into stack, so "#pragma pack(pop)" causing stack underflow. --- compiler/ccgtypes.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 24d3a0dfb4..8a60143fb7 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -496,7 +496,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, if hasAttribute in CC[cCompiler].props: add(unionBody, "struct __attribute__((__packed__)){" ) else: - addf(unionBody, "#pragma pack(1)$nstruct{", []) + addf(unionBody, "#pragma pack(push, 1)$nstruct{", []) add(unionBody, a) addf(unionBody, "} $1;$n", [sname]) if tfPacked in rectype.flags and hasAttribute notin CC[cCompiler].props: @@ -551,7 +551,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: Rope, if hasAttribute in CC[cCompiler].props: result = structOrUnion(typ) & " __attribute__((__packed__))" else: - result = "#pragma pack(1)" & tnl & structOrUnion(typ) + result = "#pragma pack(push, 1)" & tnl & structOrUnion(typ) else: result = structOrUnion(typ)