mirror of https://github.com/tinygo-org/tinygo.git
Browse Source
This commit will use the memory layout information for heap allocations added in the previous commit to determine LLVM types, instead of guessing their types based on the content. This fixes a bug in which recursive data structures (such as doubly linked lists) would result in a compiler stack overflow due to infinite recursion. Not all heap allocations have a memory layout yet, but this can be incrementally fixed in the future. So far, this commit should fix (almost?) all cases of this stack overflow issue.pull/2204/head
Ayke van Laethem
3 years ago
committed by
Ron Evans
6 changed files with 270 additions and 12 deletions
@ -0,0 +1,53 @@ |
|||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
|||
target triple = "wasm32--wasi" |
|||
|
|||
@"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c" \00\00\00\00\00\00\01" } |
|||
@pointerFree12 = global i8* null |
|||
@pointerFree7 = global i8* null |
|||
@pointerFree3 = global i8* null |
|||
@pointerFree0 = global i8* null |
|||
@layout1 = global i8* null |
|||
@layout2 = global i8* null |
|||
@layout3 = global i8* null |
|||
@layout4 = global i8* null |
|||
@bigobj1 = global i8* null |
|||
|
|||
declare i8* @runtime.alloc(i32, i8*) unnamed_addr |
|||
|
|||
define void @runtime.initAll() unnamed_addr { |
|||
call void @main.init() |
|||
ret void |
|||
} |
|||
|
|||
define internal void @main.init() unnamed_addr { |
|||
; Object that's word-aligned. |
|||
%pointerFree12 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 3 to i8*)) |
|||
store i8* %pointerFree12, i8** @pointerFree12 |
|||
; Object larger than a word but not word-aligned. |
|||
%pointerFree7 = call i8* @runtime.alloc(i32 7, i8* inttoptr (i32 3 to i8*)) |
|||
store i8* %pointerFree7, i8** @pointerFree7 |
|||
; Object smaller than a word (and of course not word-aligned). |
|||
%pointerFree3 = call i8* @runtime.alloc(i32 3, i8* inttoptr (i32 3 to i8*)) |
|||
store i8* %pointerFree3, i8** @pointerFree3 |
|||
; Zero-sized object. |
|||
%pointerFree0 = call i8* @runtime.alloc(i32 0, i8* inttoptr (i32 3 to i8*)) |
|||
store i8* %pointerFree0, i8** @pointerFree0 |
|||
|
|||
; Object made out of 3 pointers. |
|||
%layout1 = call i8* @runtime.alloc(i32 12, i8* inttoptr (i32 67 to i8*)) |
|||
store i8* %layout1, i8** @layout1 |
|||
; Array (or slice) of 5 slices. |
|||
%layout2 = call i8* @runtime.alloc(i32 60, i8* inttoptr (i32 71 to i8*)) |
|||
store i8* %layout2, i8** @layout2 |
|||
; Oddly shaped object, using all bits in the layout integer. |
|||
%layout3 = call i8* @runtime.alloc(i32 104, i8* inttoptr (i32 2467830261 to i8*)) |
|||
store i8* %layout3, i8** @layout3 |
|||
; ...repeated. |
|||
%layout4 = call i8* @runtime.alloc(i32 312, i8* inttoptr (i32 2467830261 to i8*)) |
|||
store i8* %layout4, i8** @layout4 |
|||
|
|||
; Large object that needs to be stored in a separate global. |
|||
%bigobj1 = call i8* @runtime.alloc(i32 248, i8* bitcast ({ i32, [8 x i8] }* @"runtime/gc.layout:62-2000000000000001" to i8*)) |
|||
store i8* %bigobj1, i8** @bigobj1 |
|||
ret void |
|||
} |
@ -0,0 +1,25 @@ |
|||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
|||
target triple = "wasm32--wasi" |
|||
|
|||
@pointerFree12 = local_unnamed_addr global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @"main$alloc", i32 0, i32 0) |
|||
@pointerFree7 = local_unnamed_addr global i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"main$alloc.1", i32 0, i32 0) |
|||
@pointerFree3 = local_unnamed_addr global i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"main$alloc.2", i32 0, i32 0) |
|||
@pointerFree0 = local_unnamed_addr global i8* getelementptr inbounds ([0 x i8], [0 x i8]* @"main$alloc.3", i32 0, i32 0) |
|||
@layout1 = local_unnamed_addr global i8* bitcast ([3 x i8*]* @"main$alloc.4" to i8*) |
|||
@layout2 = local_unnamed_addr global i8* bitcast ([5 x { i8*, i32, i32 }]* @"main$alloc.5" to i8*) |
|||
@layout3 = local_unnamed_addr global i8* bitcast ({ i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }* @"main$alloc.6" to i8*) |
|||
@layout4 = local_unnamed_addr global i8* bitcast ([3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }]* @"main$alloc.7" to i8*) |
|||
@bigobj1 = local_unnamed_addr global i8* bitcast ({ i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* }* @"main$alloc.8" to i8*) |
|||
@"main$alloc" = internal global [12 x i8] zeroinitializer, align 4 |
|||
@"main$alloc.1" = internal global [7 x i8] zeroinitializer, align 4 |
|||
@"main$alloc.2" = internal global [3 x i8] zeroinitializer, align 4 |
|||
@"main$alloc.3" = internal global [0 x i8] zeroinitializer, align 4 |
|||
@"main$alloc.4" = internal global [3 x i8*] zeroinitializer, align 4 |
|||
@"main$alloc.5" = internal global [5 x { i8*, i32, i32 }] zeroinitializer, align 4 |
|||
@"main$alloc.6" = internal global { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* } zeroinitializer, align 4 |
|||
@"main$alloc.7" = internal global [3 x { i8*, i8*, i8*, i32, i32, i8*, i8*, i32, i32, i32, i32, i32, i32, i8*, i8*, i32, i32, i32, i8*, i8*, i32, i32, i8*, i32, i32, i8* }] zeroinitializer, align 4 |
|||
@"main$alloc.8" = internal global { i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8* } zeroinitializer, align 4 |
|||
|
|||
define void @runtime.initAll() unnamed_addr { |
|||
ret void |
|||
} |
Loading…
Reference in new issue