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

Safety data-flow #2143

Merged
merged 15 commits into from
Mar 30, 2022
Prev Previous commit
Next Next commit
nulls
carterkozak committed Mar 29, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3ebe69704f667230cede78e24348e1f77599647b
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Symbol.VarSymbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import java.io.Closeable;
import java.util.HashMap;
@@ -636,7 +637,8 @@ public TransferResult<Safety, AccessPathStore<Safety>> visitVariableDeclaration(
public TransferResult<Safety, AccessPathStore<Safety>> visitFieldAccess(
FieldAccessNode node, TransferInput<Safety, AccessPathStore<Safety>> input) {
Safety fieldSafety = SafetyAnnotations.getSafety(ASTHelpers.getSymbol(node.getTree()), state);
Safety typeSafety = SafetyAnnotations.getSafety(ASTHelpers.getType(node.getTree()).tsym, state);
Type fieldType = ASTHelpers.getType(node.getTree());
Safety typeSafety = fieldType == null ? Safety.UNKNOWN : SafetyAnnotations.getSafety(fieldType.tsym, state);
VarSymbol symbol = (VarSymbol) ASTHelpers.getSymbol(node.getTree());
AccessPath maybeAccessPath = AccessPath.fromFieldAccess(node);
Safety flowSafety = fieldSafety(symbol, maybeAccessPath, input.getRegularStore());
@@ -705,7 +707,9 @@ public TransferResult<Safety, AccessPathStore<Safety>> visitStringConversion(
public TransferResult<Safety, AccessPathStore<Safety>> visitWideningConversion(
WideningConversionNode node, TransferInput<Safety, AccessPathStore<Safety>> input) {
Safety valueSafety = input.getValueOfSubNode(node.getOperand());
Safety widenTargetSafety = SafetyAnnotations.getSafety(ASTHelpers.getType(node.getTree()).tsym, state);
Type widenTarget = ASTHelpers.getType(node.getTree());
Safety widenTargetSafety =
widenTarget == null ? Safety.UNKNOWN : SafetyAnnotations.getSafety(widenTarget.tsym, state);
Safety resultSafety = Safety.mergeAssumingUnknownIsSame(valueSafety, widenTargetSafety);
return noStoreChanges(resultSafety, input);
}
@@ -714,7 +718,9 @@ public TransferResult<Safety, AccessPathStore<Safety>> visitWideningConversion(
public TransferResult<Safety, AccessPathStore<Safety>> visitNarrowingConversion(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: visitWideningConversion and visitNarrowingConversion uses the same code. Maybe we can extract or delegate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I'll include visitTypeCast as well

NarrowingConversionNode node, TransferInput<Safety, AccessPathStore<Safety>> input) {
Safety valueSafety = input.getValueOfSubNode(node.getOperand());
Safety narrowTargetSafety = SafetyAnnotations.getSafety(ASTHelpers.getType(node.getTree()).tsym, state);
Type narrowTarget = ASTHelpers.getType(node.getTree());
Safety narrowTargetSafety =
narrowTarget == null ? Safety.UNKNOWN : SafetyAnnotations.getSafety(narrowTarget.tsym, state);
Safety resultSafety = Safety.mergeAssumingUnknownIsSame(valueSafety, narrowTargetSafety);
return noStoreChanges(resultSafety, input);
}
@@ -730,7 +736,9 @@ public TransferResult<Safety, AccessPathStore<Safety>> visitTypeCast(
TypeCastNode node, TransferInput<Safety, AccessPathStore<Safety>> input) {
Safety valueSafety = input.getValueOfSubNode(node.getOperand());
TypeCastTree castTree = (TypeCastTree) node.getTree();
Safety castTargetSafety = SafetyAnnotations.getSafety(ASTHelpers.getType(castTree.getType()).tsym, state);
Type castTarget = ASTHelpers.getType(castTree.getType());
Safety castTargetSafety =
castTarget == null ? Safety.UNKNOWN : SafetyAnnotations.getSafety(castTarget.tsym, state);
Safety resultSafety = Safety.mergeAssumingUnknownIsSame(valueSafety, castTargetSafety);
return noStoreChanges(resultSafety, input);
}