aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-12-09 20:09:11 -0800
committerAlon Zakai <azakai@mozilla.com>2010-12-09 20:09:11 -0800
commit1c5355c76c0389775f3e11b5b962311e7501ad31 (patch)
treefda230be1c9214bf6b2e7d9dda016fa0fd70a7e9 /tests
parent023a34753e1e47f03eadfd91a7e639afbbead888 (diff)
proper support for bitfields
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/trunc.ll25
-rw-r--r--tests/cases/trunc.txt1
-rw-r--r--tests/runner.py41
3 files changed, 63 insertions, 4 deletions
diff --git a/tests/cases/trunc.ll b/tests/cases/trunc.ll
new file mode 100644
index 00000000..6af3656c
--- /dev/null
+++ b/tests/cases/trunc.ll
@@ -0,0 +1,25 @@
+; ModuleID = '/tmp/emscripten/tmp/src.cpp.o'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private constant [8 x i8] c"*%d,%d*\0A\00", align 1 ; [#uses=1]
+
+; [#uses=1]
+declare i32 @printf(i8*)
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %retval = alloca i32 ; [#uses=2]
+ %0 = alloca i32 ; [#uses=2]
+ %"alloca point" = bitcast i32 0 to i32 ; [#uses=0]
+ store i32 4, i32* %0, align 4
+ %1 = load i32* %0, align 4 ; [#uses=1]
+ %2 = trunc i8 %1 to i1 ; [#uses=1]
+ %3 = call i32 @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0), i32 %1, i32 %2) ; [#uses=0]
+ br label %return
+
+return: ; preds = %entry
+ %retval1 = load i32* %retval ; [#uses=1]
+ ret i32 %retval1
+}
diff --git a/tests/cases/trunc.txt b/tests/cases/trunc.txt
new file mode 100644
index 00000000..dddcc3f5
--- /dev/null
+++ b/tests/cases/trunc.txt
@@ -0,0 +1 @@
+*4,0*
diff --git a/tests/runner.py b/tests/runner.py
index d523dbba..22a817bd 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -5,7 +5,7 @@ See settings.py file for options&params. Edit as needed.
'''
from subprocess import Popen, PIPE, STDOUT
-import os, unittest, tempfile, shutil, time, inspect, sys, math
+import os, unittest, tempfile, shutil, time, inspect, sys, math, glob
# Params
@@ -200,6 +200,33 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, '*4294967295,0,4294967219*')
+ def test_bitfields(self):
+ global SAFE_HEAP; SAFE_HEAP = 0 # bitfields do loads on invalid areas, by design
+ src = '''
+ #include <stdio.h>
+ struct bitty {
+ unsigned x : 1;
+ unsigned y : 1;
+ unsigned z : 1;
+ };
+ int main()
+ {
+ bitty b;
+ printf("*");
+ for (int i = 0; i <= 1; i++)
+ for (int j = 0; j <= 1; j++)
+ for (int k = 0; k <= 1; k++) {
+ b.x = i;
+ b.y = j;
+ b.z = k;
+ printf("%d,%d,%d,", b.x, b.y, b.z);
+ }
+ printf("*\\n");
+ return 0;
+ }
+ '''
+ self.do_test(src, '*0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,1,1,0,1,1,1,*')
+
def test_floatvars(self):
src = '''
#include <stdio.h>
@@ -1211,9 +1238,15 @@ if 'benchmark' not in sys.argv:
### Test cases in separate files
def test_cases(self):
- for name in os.listdir(path_from_root(['tests', 'cases'])):
- print "Testing case '%s'..." % name.replace('.ll', '')
- self.do_ll_test(path_from_root(['tests', 'cases', name]), 'hello, world!')
+ for name in glob.glob(path_from_root(['tests', 'cases', '*.ll'])):
+ shortname = name.replace('.ll', '')
+ print "Testing case '%s'..." % shortname
+ output_file = path_from_root(['tests', 'cases', shortname + '.txt'])
+ if os.path.exists(output_file):
+ output = open(output_file, 'r').read()
+ else:
+ output = 'hello, world!'
+ self.do_ll_test(path_from_root(['tests', 'cases', name]), output)
### Integration tests