Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
Add lint pass to detect deletion of immutable memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Oct 26, 2012
1 parent ade8b95 commit 6894b41
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/mci/verifier/lint.d
Expand Up @@ -139,6 +139,7 @@ shared static this()
passes.add((fn, msgs) => lintLeakingStackAllocatedMemory(fn, msgs));
passes.add((fn, msgs) => lintReturningFromNoReturnFunction(fn, msgs));
passes.add((fn, msgs) => lintThrowingInNoThrowFunction(fn, msgs));
passes.add((fn, msgs) => lintDeletingImmutableMemory(fn, msgs));

standardPasses = passes;
}
Expand Down Expand Up @@ -251,3 +252,28 @@ body
if (insn.opCode is opEHThrow || insn.opCode is opEHRethrow)
message(messages, insn, "Throwing in a nothrow function.");
}

private void lintDeletingImmutableMemory(Function function_, NoNullList!LintMessage messages)
in
{
assert(function_);
assert(function_.attributes & FunctionAttributes.ssa);
assert(messages);
}
body
{
foreach (bb; function_.blocks)
{
foreach (insn; bb.y.stream)
{
if (insn.opCode is opMemFree)
{
auto def = first(insn.sourceRegister1.definitions);

if (def.opCode is opLoadData || def.opCode is opFieldGlobalAddr || def.opCode is opFieldThreadAddr || def.opCode is opMemAddr ||
(def.opCode is opFieldAddr && cast(StructureType)def.sourceRegister1.type))
message(messages, insn, "Deleting immutable memory (data block, stack, or global/thread field memory).");
}
}
}
}

0 comments on commit 6894b41

Please sign in to comment.