-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leaks in quantifier expressions early exits
TN: UB12-016
- Loading branch information
Showing
7 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
testsuite/tests/properties/quantifier_refcount/expected_concrete_syntax.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import lexer_example | ||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- list+(Example(@example)) | ||
|
||
} | ||
|
||
@abstract class FooNode implements Node[FooNode] { | ||
|
||
fun get_bigint(): BigInt = BigInt(1) | ||
|
||
@export fun check(): Bool = node.children.all( | ||
(c) => # This condition is always False, so we have a loop early exit, | ||
# which used to leave the result of "c.get_bigint" (big integers | ||
# are ref-counted) allocated when exitting the scope: the finalizer | ||
# for that scope was not called in that case. | ||
c.get_bigint() = BigInt(0) | ||
) | ||
} | ||
|
||
class Example : FooNode implements TokenNode { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
with Ada.Text_IO; use Ada.Text_IO; | ||
|
||
with Libfoolang.Analysis; use Libfoolang.Analysis; | ||
|
||
procedure Main is | ||
Ctx : constant Analysis_Context := Create_Context; | ||
U : constant Analysis_Unit := Ctx.Get_From_Buffer | ||
(Filename => "main.txt", | ||
Buffer => "example"); | ||
N : constant Foo_Node := U.Root; | ||
|
||
begin | ||
if U.Has_Diagnostics then | ||
for D of U.Diagnostics loop | ||
Put_Line (U.Format_GNU_Diagnostic (D)); | ||
end loop; | ||
raise Program_Error; | ||
end if; | ||
|
||
Put_Line ("P_Check (" & N.Image & ") = " & N.P_Check'Image); | ||
end Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
P_Check (<ExampleList main.txt:1:1-1:8>) = FALSE | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Check that the scope of a Qualifier expression is correctly finalized on early | ||
exit. | ||
""" | ||
|
||
from langkit.dsl import ASTNode | ||
from langkit.expressions import BigIntLiteral, Self, langkit_property | ||
|
||
from utils import build_and_run | ||
|
||
|
||
class FooNode(ASTNode): | ||
|
||
@langkit_property() | ||
def get_bigint(): | ||
return BigIntLiteral(1) | ||
|
||
@langkit_property(public=True) | ||
def check(): | ||
return Self.children.all( | ||
# This condition is always False, so we have a loop early exit, | ||
# which used to leave the result of "c.get_bigint" (big integers | ||
# are ref-counted) allocated when exitting the scope: the finalizer | ||
# for that scope was not called in that case. | ||
lambda c: c.get_bigint() == BigIntLiteral(0) | ||
) | ||
|
||
|
||
class Example(FooNode): | ||
token_node = True | ||
|
||
|
||
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main="main.adb", | ||
types_from_lkt=False) | ||
print('Done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver: python |