aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-23 20:26:44 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-23 20:26:44 -0700
commit099f970ee705dd2e45cc59388ad3642bf93fea7d (patch)
tree401b1c00c9f33e7f3f1f48cf2edb1c05051d6e61
parenteb9e6cb27251d56adbe03eceeee595b5e3ce93f7 (diff)
properly handle generation of instances of structures ending in [0 x ..]
-rw-r--r--src/parseTools.js6
-rw-r--r--src/runtime.js10
-rw-r--r--tests/cases/zeroembedded.ll7
3 files changed, 16 insertions, 7 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 3f7bd421..72166592 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -969,6 +969,12 @@ function generateStructTypes(type) {
}
ret[index++] = type;
} else {
+ if (Runtime.isStructType(type) && type[1] === '0') {
+ // this is [0 x something]. When inside another structure like here, it must be at the end,
+ // and it does nothing
+ assert(i === typeData.fields.length-1);
+ return;
+ }
add(Types.types[type]);
}
var more = (i+1 < typeData.fields.length ? typeData.flatIndexes[i+1] : typeData.flatSize) - (index - start);
diff --git a/src/runtime.js b/src/runtime.js
index 062066af..8c2c8f4d 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -214,7 +214,7 @@ var Runtime = {
// and it adds no size
assert(index === type.fields.length);
size = 0;
- alignSize = 0;
+ alignSize = type.alignSize || QUANTUM_SIZE;
} else {
size = Types.types[field].flatSize;
alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
@@ -228,12 +228,8 @@ var Runtime = {
}
if (type.packed) alignSize = 1;
type.alignSize = Math.max(type.alignSize, alignSize);
- if (size > 0) {
- var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
- type.flatSize = curr + size;
- } else {
- curr = prev;
- }
+ var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
+ type.flatSize = curr + size;
if (prev >= 0) {
diffs.push(curr-prev);
}
diff --git a/tests/cases/zeroembedded.ll b/tests/cases/zeroembedded.ll
index c1ffa212..6a4f6073 100644
--- a/tests/cases/zeroembedded.ll
+++ b/tests/cases/zeroembedded.ll
@@ -2,15 +2,22 @@
%struct.pypy_str = type { i32, [0 x i8] }
%struct.pypy_strval = type { i32, [13 x i8] }
+%union.pypy_array3_len0u = type { %struct.pypy_array3_len0 }
+%struct.pypy_array3_len0 = type { i32, i32, [0 x i8] }
+
@pypy_g_strval = global %struct.pypy_strval { i32 13, [13 x i8] c"hello world\0A\00" }
+@pypy_g_strval2 = global %struct.pypy_array3_len0 { i32 13, i32 111, [0 x i8] c"" }
declare i32 @printf(i8*, ...)
define i32 @main(i32 %argc, i8** nocapture %argv) {
+ %waka = alloca %struct.pypy_array3_len0
%1 = bitcast %struct.pypy_strval* @pypy_g_strval to %struct.pypy_str*
%2 = getelementptr inbounds %struct.pypy_str* %1, i32 1
%3 = bitcast %struct.pypy_str* %2 to i8*
call i32 (i8*, ...)* @printf(i8* %3)
+ %unneeded = bitcast %struct.pypy_str* %2 to %struct.pypy_array3_len0*
+ call i32 (i8*, ...)* @printf(i8* %3, %struct.pypy_array3_len0* %unneeded)
ret i32 0
}