Skip to content

Commit 68d23c6

Browse files
committed
properly identify function pointers that return things like [64 x i16]*
1 parent c055544 commit 68d23c6

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/parseTools.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ function isFunctionDef(token, out) {
169169

170170
function isFunctionType(type, out) {
171171
type = type.replace(/"[^"]+"/g, '".."');
172-
var parts = type.split(' ');
172+
var parts;
173+
// hackish, but quick splitting of function def parts. this must be fast as it happens a lot
174+
if (type[0] != '[') {
175+
parts = type.split(' ');
176+
} else {
177+
var index = type.search(']');
178+
index += type.substr(index).search(' ');
179+
parts = [type.substr(0, index), type.substr(index+1)];
180+
}
173181
if (pointingLevels(type) !== 1) return false;
174182
var text = removeAllPointing(parts.slice(1).join(' '));
175183
if (!text) return false;

tests/cases/funcptr.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; ModuleID = 'tests/hello_world.bc'
2+
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-S128"
3+
target triple = "i386-pc-linux-gnu"
4+
5+
@.str = private unnamed_addr constant [17 x i8] c"hello %d world!\0A\00", align 1 ; [#uses=1 type=[17 x i8]*]
6+
7+
; [#uses=0]
8+
define i32 @main() {
9+
entry:
10+
%retval = alloca i32, align 4 ; [#uses=1 type=i32*]
11+
store i32 0, i32* %retval
12+
%access_virt_barray = bitcast i32 0 to [64 x i16]* (i32*, i32)**
13+
store [64 x i16]* (i32*, i32)* @access_virt_barray, [64 x i16]* (i32*, i32)** %access_virt_barray, align 4
14+
%wakaptr = bitcast [64 x i16]* (i32*, i32)** %access_virt_barray to i32*
15+
%waka = load i32* %wakaptr
16+
%waka2 = icmp eq i32 %waka, 0
17+
%waka3 = zext i1 %waka2 to i32
18+
%call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @.str, i32 0, i32 0), i32 %waka3) ; [#uses=0 type=i32]
19+
ret i32 1
20+
}
21+
22+
define [64 x i16]* @access_virt_barray(i32*, i32) {
23+
ret void
24+
}
25+
26+
; [#uses=1]
27+
declare i32 @printf(i8*, ...)

tests/cases/funcptr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello 0 world!

0 commit comments

Comments
 (0)