Skip to content

Commit

Permalink
Fix uninitialized memory when using %domain construct.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roldak committed Sep 16, 2024
1 parent 0fe6e6c commit ee8b0a8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
4 changes: 3 additions & 1 deletion langkit/templates/properties/domain_ada.mako
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ begin
if element_type.is_entity_type else
element_type)
node_expr = 'Item.Node' if element_type.is_entity_type else 'Item'
info_expr = 'Item.Info' if element_type.is_entity_type else '<>'
info_expr = ('Item.Info'
if element_type.is_entity_type else
'No_Entity_Info')
%>
Item : constant ${element_type.name} := Get (Self, Dom, J);
begin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import lexer_example

@with_lexer(foo_lexer)
grammar foo_grammar {
@main_rule main_rule <- Example("example")
}

@abstract
class FooNode implements Node[FooNode] {
v: LogicVar
}

class Example: FooNode {
fun identity(): Entity[Example] = self

@exported
fun test(): Bool = (
%domain(node.v, [node]) and %eq(node.v, node.v, conv_prop=Example.identity)
).solve()
}
19 changes: 19 additions & 0 deletions testsuite/tests/properties/domain_node/main.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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");

Node : constant Example := U.Root.As_Example;
Dummy : Boolean;
begin
if U.Has_Diagnostics then
Put_Line ("Parsing errors...");
return;
end if;
Dummy := Node.P_Test;
Put_Line ("main.adb: Done.");
end Main;
2 changes: 2 additions & 0 deletions testsuite/tests/properties/domain_node/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main.adb: Done.
Done
32 changes: 32 additions & 0 deletions testsuite/tests/properties/domain_node/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Test that using the ``domain`` DSL construct with bare nodes does not set
uninitialized data into the corresponding logic variable.
"""

from langkit.dsl import ASTNode, T, UserField
from langkit.expressions import Bind, Entity, Self, langkit_property

from utils import build_and_run


class FooNode(ASTNode):
v = UserField(type=T.LogicVar, public=False)


class Example(FooNode):
@langkit_property(return_type=T.Example.entity)
def identity():
return Entity

@langkit_property(public=True)
def test():
return (Self.v.domain([Self]) &
Bind(Self.v, Self.v, conv_prop=Example.identity)).solve


build_and_run(
lkt_file='expected_concrete_syntax.lkt',
gpr_mains=['main.adb'],
types_from_lkt=True,
)
print('Done')
1 change: 1 addition & 0 deletions testsuite/tests/properties/domain_node/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
driver: python

0 comments on commit ee8b0a8

Please sign in to comment.