Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent creating return commands with empty tokens when copying blocks #926

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/Core/AST/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public bool IsLive(Variable v)
return liveVarsBefore.Contains(v);
}

public Block()
: this(Token.NoToken, "", new List<Cmd>(), new ReturnCmd(Token.NoToken))
public Block(IToken tok)
: this(tok, "", new List<Cmd>(), new ReturnCmd(tok))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have more location information!

{
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VariableDependenceAnalyser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ private Dictionary<Block, HashSet<Block>> ComputeGlobalControlDependences()
foreach (var Impl in prog.NonInlinedImplementations())
{
Graph<Block> blockGraph = prog.ProcessLoops(options, Impl);
LocalCtrlDeps[Impl] = blockGraph.ControlDependence();
LocalCtrlDeps[Impl] = blockGraph.ControlDependence(new Block(prog.tok));
foreach (var KeyValue in LocalCtrlDeps[Impl])
{
GlobalCtrlDep.Add(KeyValue.Key, KeyValue.Value);
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- Target framework and package configuration -->
<PropertyGroup>
<Version>3.2.3</Version>
<Version>3.2.4</Version>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>Boogie</Authors>
Expand Down
6 changes: 3 additions & 3 deletions Source/Graph/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ public static IEnumerable<object> FindReachableNodesInGraphWithMergeNodes(

public static Graph<Node> Dual<Node>(this Graph<Node> g, Node dummySource)
{
var exits = g.Nodes.Where(n => g.Successors(n).Count() == 0).ToList();
var exits = g.Nodes.Where(n => !g.Successors(n).Any()).ToList();
Node source;
if (exits.Count == 0)
{
Expand Down Expand Up @@ -1373,9 +1373,9 @@ public static List<Tuple<Node, bool>> LoopyTopSort<Node>(this Graph<Node> g)

// Algorithm from Jeanne Ferrante, Karl J. Ottenstein, Joe D. Warren,
// "The Program Dependence Graph and Its Use in Optimization"
public static Dictionary<Node, HashSet<Node>> ControlDependence<Node>(this Graph<Node> g) where Node : class, new()
public static Dictionary<Node, HashSet<Node>> ControlDependence<Node>(this Graph<Node> g, Node dummySource) where Node : class
{
Graph<Node> dual = g.Dual(new Node());
Graph<Node> dual = g.Dual(dummySource);
DomRelation<Node> pdom = dual.DominatorMap;

var result = new Dictionary<Node, HashSet<Node>>();
Expand Down
32 changes: 19 additions & 13 deletions Source/VCGeneration/LoopExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ static void CreateProceduresForLoops(CoreOptions options, Implementation impl, G
continue;
}

Block newBlock = new Block();
newBlock.Label = block.Label;
Block newBlock = new Block(block.tok)
{
Label = block.Label
};
if (headRecursion && block == header)
{
CallCmd callCmd = (CallCmd) (loopHeaderToCallCmd2[header]).Clone();
Expand All @@ -330,10 +332,13 @@ static void CreateProceduresForLoops(CoreOptions options, Implementation impl, G
blockMap[block] = newBlock;
if (newBlocksCreated.ContainsKey(block))
{
Block newBlock2 = new Block();
newBlock2.Label = newBlocksCreated[block].Label;
newBlock2.Cmds = Substituter.Apply(subst, newBlocksCreated[block].Cmds);
blockMap[newBlocksCreated[block]] = newBlock2;
var original = newBlocksCreated[block];
var newBlock2 = new Block(original.tok)
{
Label = original.Label,
Cmds = Substituter.Apply(subst, original.Cmds)
};
blockMap[original] = newBlock2;
}

//for detLoopExtract, need the immediate successors even outside the loop
Expand All @@ -349,15 +354,16 @@ static void CreateProceduresForLoops(CoreOptions options, Implementation impl, G
if (g.Nodes.Contains(bl) && //newly created blocks are not present in NaturalLoop(header, xx, g)
!loopNodes.Contains(bl))
{
Block auxNewBlock = new Block();
auxNewBlock.Label = bl.Label;
//these blocks may have read/write locals that are not present in naturalLoops
//we need to capture these variables
auxNewBlock.Cmds = Substituter.Apply(subst, bl.Cmds);
var auxNewBlock = new Block(bl.tok)
{
Label = bl.Label,
//these blocks may have read/write locals that are not present in naturalLoops
//we need to capture these variables
Cmds = Substituter.Apply(subst, bl.Cmds)
};
//add restoration code for such blocks
if (loopHeaderToAssignCmd.ContainsKey(header))
if (loopHeaderToAssignCmd.TryGetValue(header, out var assignCmd))
{
AssignCmd assignCmd = loopHeaderToAssignCmd[header];
auxNewBlock.Cmds.Add(assignCmd);
}

Expand Down
9 changes: 5 additions & 4 deletions Source/VCGeneration/ManualSplitFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ private static List<Block> DoPreAssignedManualSplit(VCGenOptions options, List<B
//var duplicator = new Duplicator();
var oldToNewBlockMap = new Dictionary<Block, Block>(blocks.Count); // Maps original blocks to their new copies in newBlocks
foreach (var currentBlock in blocks) {
var newBlock = new Block();
newBlock.Label = currentBlock.Label;
newBlock.tok = currentBlock.tok;

var newBlock = new Block(currentBlock.tok)
{
Label = currentBlock.Label
};

oldToNewBlockMap[currentBlock] = newBlock;
newBlocks.Add(newBlock);
if (currentBlock == containingBlock) {
Expand Down
Loading