aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/intertyper.js6
-rw-r--r--src/parseTools.js2
-rw-r--r--tests/cases/ptrtoi64.ll25
-rw-r--r--tests/cases/ptrtoi64.txt1
4 files changed, 31 insertions, 3 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 4b4544ae..c9580319 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -815,8 +815,10 @@ function intertyper(data, sidePass, baseLineNums) {
} else {
item.type = item.param1.type;
}
- for (var i = 1; i <= 4; i++) {
- if (item['param'+i]) item['param'+i].type = item.type; // All params have the same type, normally
+ if (item.op != 'ptrtoint') {
+ for (var i = 1; i <= 4; i++) {
+ if (item['param'+i]) item['param'+i].type = item.type; // All params have the same type, normally
+ }
}
if (item.op in LLVM.EXTENDS) {
item.type = item.param2.ident;
diff --git a/src/parseTools.js b/src/parseTools.js
index 7f837419..88c7ce68 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1652,7 +1652,7 @@ function processMathop(item) {
return '((' + ident1 + '[0]) & ' + (Math.pow(2, bitsLeft)-1) + ')';
}
case 'select': return ident1 + ' ? ' + makeCopyI64(ident2) + ' : ' + makeCopyI64(ident3);
- case 'ptrtoint': throw 'Pointers cannot be 64-bit!';
+ case 'ptrtoint': return makeI64(ident1, 0);
case 'inttoptr': return '(' + ident1 + '[0])'; // just directly truncate the i64 to a 'pointer', which is an i32
// Dangerous, rounded operations. TODO: Fully emulate
case 'add': warnI64_1(); return handleOverflow(splitI64(mergeI64(ident1) + '+' + mergeI64(ident2)), bits);
diff --git a/tests/cases/ptrtoi64.ll b/tests/cases/ptrtoi64.ll
new file mode 100644
index 00000000..a820efc4
--- /dev/null
+++ b/tests/cases/ptrtoi64.ll
@@ -0,0 +1,25 @@
+; pointer to i64, then to i32
+
+; 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"
+
+@.str2 = private constant [6 x i8] c"*%d*\0A\00", align 1 ; [#uses=1]
+
+; [#uses=1]
+declare i32 @puts(i8*)
+
+declare i32 @printf(i8* noalias, ...) nounwind
+
+; [#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]
+ %sz.i7 = inttoptr i32 512 to i32* ; [#uses=1 type=i32*]
+ %10 = ptrtoint i32* %sz.i7 to i64, !dbg !8557 ; [#uses=1 type=i64] [debug line = 99:3]
+ %conv5 = trunc i64 %10 to i32, !dbg !8557 ; [#uses=1 type=i32] [debug line = 99:3]
+ %55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i32 %conv5) ; [#uses=0]
+ ret i32 0
+}
diff --git a/tests/cases/ptrtoi64.txt b/tests/cases/ptrtoi64.txt
new file mode 100644
index 00000000..6e1c004a
--- /dev/null
+++ b/tests/cases/ptrtoi64.txt
@@ -0,0 +1 @@
+*512*