Skip to content

Commit

Permalink
[debug] Forbade getting llvm for external non-exported functions + test
Browse files Browse the repository at this point in the history
This could happen for inline lambdas
  • Loading branch information
homuroll committed Apr 22, 2020
1 parent f00cbc2 commit 777e6e8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,12 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
private fun IrFunction.scope(startLine:Int): DIScopeOpaqueRef? {
if (!context.shouldContainLocationDebugInfo())
return null
val functionLlvmValue = codegen.llvmFunctionOrNull(this)
val functionLlvmValue =
// TODO: May be tie up inline lambdas to their outer function?
if (codegen.isExternal(this) && !KonanBinaryInterface.isExported(this))
null
else
codegen.llvmFunctionOrNull(this)
return if (!isReifiedInline && functionLlvmValue != null) {
context.debugInfo.subprograms.getOrPut(functionLlvmValue) {
memScoped {
Expand Down
5 changes: 5 additions & 0 deletions backend.native/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,11 @@ linkTest("inline_lateinitProperty_linkTest") {
lib = "codegen/inline/lateinitProperty_linkTest_lib.kt"
}

linkTest("inline_inlineCtor_linkTest") {
source = "codegen/inline/inlineCtor_linkTest_main.kt"
lib = "codegen/inline/inlineCtor_linkTest_lib.kt"
}

def generateWithSpaceDefFile() {
def mapOption = "--Map \"${buildDir}/cutom map.map\""
if (isAppleTarget(project)) {
Expand Down
13 changes: 13 additions & 0 deletions backend.native/tests/codegen/inline/inlineCtor_linkTest_lib.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/

package a

fun foo(n: Int, block: (Int) -> Int): Int {
val arr = IntArray(n) { block(it) }
var sum = 0
for (x in arr) sum += x
return sum
}
11 changes: 11 additions & 0 deletions backend.native/tests/codegen/inline/inlineCtor_linkTest_main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/

import a.*
import kotlin.test.*

fun main() {
assertEquals(42, foo(7) { it * 2 })
}

0 comments on commit 777e6e8

Please sign in to comment.