summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorsleepyqt <sleepyqt@users.noreply.github.com>2018-01-10 01:02:09 +0300
committerAndreas Rumpf <rumpf_a@web.de>2018-01-09 23:02:09 +0100
commita54430ea2dc7d39670e0451a04d3b9f349ae8072 (patch)
treea553a1f5a84603500777e45b14cb3e4417fe04d4
parente7e37713dda4017d2f8fb2f1c9481194314e9d60 (diff)
downloadNim-a54430ea2dc7d39670e0451a04d3b9f349ae8072.tar.gz
Fix struct packing for VCC. (#7049)
"#pragma pack(1)" sets current alligment without pushing into stack,
so "#pragma pack(pop)" causing stack underflow.
-rw-r--r--compiler/ccgtypes.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 24d3a0dfb..8a60143fb 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)