-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++/C#: Make escape analysis unsound by default #2667
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
Changes from all commits
9d35ff7
5ae1e2c
66914e5
708e835
6988241
40952f8
3b35020
7df3cf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import IRConfiguration | ||
|
||
/** | ||
* Overrides the default IR configuration to use sound escape analysis, instead of assuming that | ||
* variable addresses never escape. | ||
*/ | ||
class SoundEscapeAnalysisConfiguration extends IREscapeAnalysisConfiguration { | ||
override predicate useSoundEscapeAnalysis() { any() } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1932,47 +1932,31 @@ abstract class TranslatedThrowExpr extends TranslatedNonConstantExpr { | |
* IR translation of a `throw` expression with an argument | ||
* (e.g. `throw std::bad_alloc()`). | ||
*/ | ||
class TranslatedThrowValueExpr extends TranslatedThrowExpr, InitializationContext { | ||
class TranslatedThrowValueExpr extends TranslatedThrowExpr, TranslatedVariableInitialization { | ||
TranslatedThrowValueExpr() { not expr instanceof ReThrowExpr } | ||
|
||
override TranslatedElement getChild(int id) { id = 0 and result = getInitialization() } | ||
|
||
override Instruction getFirstInstruction() { | ||
result = getInstruction(InitializerVariableAddressTag()) | ||
} | ||
|
||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) { | ||
TranslatedThrowExpr.super.hasInstruction(opcode, tag, resultType) | ||
or | ||
tag = InitializerVariableAddressTag() and | ||
opcode instanceof Opcode::VariableAddress and | ||
resultType = getTypeForGLValue(getExceptionType()) | ||
TranslatedVariableInitialization.super.hasInstruction(opcode, tag, resultType) | ||
} | ||
|
||
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) { | ||
result = TranslatedThrowExpr.super.getInstructionSuccessor(tag, kind) | ||
or | ||
tag = InitializerVariableAddressTag() and | ||
result = getInitialization().getFirstInstruction() and | ||
kind instanceof GotoEdge | ||
} | ||
|
||
override Instruction getChildSuccessor(TranslatedElement child) { | ||
child = getInitialization() and | ||
result = getInstruction(ThrowTag()) | ||
result = TranslatedVariableInitialization.super.getInstructionSuccessor(tag, kind) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand what's going on here (the successor relations within each piece are exactly the ones in the respective superclass, and the connection between them is injected into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a cleaner way of doing this would have been to make the actual (un)initialization part a separate element that is a child of the original element, i.e., composition instead of inheritance. That seemed like an even bigger refactoring in a change where I hadn't expected to do any refactoring to begin with. I can go back and improve this, but I'd prefer to do it in a follow-up post-January. |
||
} | ||
|
||
override IRVariable getInstructionVariable(InstructionTag tag) { | ||
tag = InitializerVariableAddressTag() and | ||
result = getIRTempVariable(expr, ThrowTempVar()) | ||
} | ||
final override Instruction getInitializationSuccessor() { result = getInstruction(ThrowTag()) } | ||
|
||
final override predicate hasTempVariable(TempVariableTag tag, CppType type) { | ||
tag = ThrowTempVar() and | ||
type = getTypeForPRValue(getExceptionType()) | ||
} | ||
|
||
final override Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) { | ||
result = TranslatedVariableInitialization.super.getInstructionOperand(tag, operandTag) | ||
or | ||
tag = ThrowTag() and | ||
( | ||
operandTag instanceof AddressOperandTag and | ||
|
@@ -1989,16 +1973,14 @@ class TranslatedThrowValueExpr extends TranslatedThrowExpr, InitializationContex | |
result = getTypeForPRValue(getExceptionType()) | ||
} | ||
|
||
override Instruction getTargetAddress() { | ||
result = getInstruction(InitializerVariableAddressTag()) | ||
} | ||
|
||
override Type getTargetType() { result = getExceptionType() } | ||
|
||
TranslatedInitialization getInitialization() { | ||
final override TranslatedInitialization getInitialization() { | ||
result = getTranslatedInitialization(expr.getExpr().getFullyConverted()) | ||
} | ||
|
||
final override IRVariable getIRVariable() { result = getIRTempVariable(expr, ThrowTempVar()) } | ||
|
||
final override Opcode getThrowOpcode() { result instanceof Opcode::ThrowValue } | ||
|
||
private Type getExceptionType() { result = expr.getType() } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a rename without an associated change to what the values of the class are. Is that just a clarification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.