-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Handle field initialization via NSDMI in IR generation #21391
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 5 commits
5aabd90
07603a8
59c27a2
68039ec
09f930f
9e60e12
b91a52a
e986d89
22eda4e
f3fc80a
b554d7d
4a637cb
0f44d6a
49c5cc0
db7c619
dad517f
346ab9d
ef780c1
ab1f0c1
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 |
|---|---|---|
|
|
@@ -36,7 +36,8 @@ abstract class TranslatedCondition extends TranslatedElement { | |
| final override Declaration getFunction() { | ||
| result = getEnclosingFunction(expr) or | ||
| result = getEnclosingVariable(expr).(GlobalOrNamespaceVariable) or | ||
| result = getEnclosingVariable(expr).(StaticInitializedStaticLocalVariable) | ||
| result = getEnclosingVariable(expr).(StaticInitializedStaticLocalVariable) or | ||
| result = getEnclosingVariable(expr).(Field) | ||
|
Comment on lines
37
to
+40
Contributor
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. At some point we should probably have some kind of abstract class thingie instead of having to enumerate all the possible Doesn't have to be now, though, of course!
Contributor
Author
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. Agreed. I like leaving that as a follow-up. |
||
| } | ||
|
|
||
| final Type getResultType() { result = expr.getUnspecifiedType() } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ private import TranslatedFunction | |
| private import TranslatedInitialization | ||
| private import TranslatedStmt | ||
| private import TranslatedGlobalVar | ||
| private import TranslatedNonStaticDataMember | ||
| private import IRConstruction | ||
| import TranslatedCall | ||
|
|
||
|
|
@@ -138,6 +139,8 @@ abstract class TranslatedExpr extends TranslatedElement { | |
| result = getTranslatedFunction(getEnclosingFunction(expr)) | ||
| or | ||
| result = getTranslatedVarInit(getEnclosingVariable(expr)) | ||
| or | ||
| result = getTranslatedFieldInit(getEnclosingVariable(expr)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -153,7 +156,10 @@ Declaration getEnclosingDeclaration0(Expr e) { | |
| i.getExpr().getFullyConverted() = e and | ||
| v = i.getDeclaration() | ||
| | | ||
| if v instanceof StaticInitializedStaticLocalVariable or v instanceof GlobalOrNamespaceVariable | ||
| if | ||
| v instanceof StaticInitializedStaticLocalVariable or | ||
| v instanceof GlobalOrNamespaceVariable or | ||
| v instanceof Field | ||
| then result = v | ||
| else result = e.getEnclosingDeclaration() | ||
| ) | ||
|
|
@@ -173,7 +179,10 @@ Variable getEnclosingVariable0(Expr e) { | |
| i.getExpr().getFullyConverted() = e and | ||
| v = i.getDeclaration() | ||
| | | ||
| if v instanceof StaticInitializedStaticLocalVariable or v instanceof GlobalOrNamespaceVariable | ||
| if | ||
| v instanceof StaticInitializedStaticLocalVariable or | ||
| v instanceof GlobalOrNamespaceVariable or | ||
| v instanceof Field | ||
| then result = v | ||
| else result = e.getEnclosingVariable() | ||
| ) | ||
|
|
@@ -826,6 +835,46 @@ class TranslatedPostfixCrementOperation extends TranslatedCrementOperation { | |
| override Instruction getResult() { result = this.getLoadedOperand().getResult() } | ||
| } | ||
|
|
||
| class TranslatedParamAccessForType extends TranslatedNonConstantExpr { | ||
|
Contributor
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. The name here feels too broad if it only handles
Contributor
Author
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. Leaving as-is, as this matches the rest of the code.
Contributor
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 it would help the reader and whoever will have to touch the code in the future very much, but that's just my opinion 😄
Contributor
Author
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. From my perspective it will make it more difficult to find the place when we need to change things if we would ever need to expand on this. |
||
| override ParamAccessForType expr; | ||
|
|
||
| TranslatedParamAccessForType() { | ||
| // Currently only needed for this parameter accesses. | ||
| expr.isThisAccess() | ||
| } | ||
|
|
||
| final override Instruction getFirstInstruction(EdgeKind kind) { | ||
| result = this.getInstruction(OnlyInstructionTag()) and | ||
| kind instanceof GotoEdge | ||
| } | ||
|
|
||
| override Instruction getALastInstructionInternal() { | ||
| result = this.getInstruction(OnlyInstructionTag()) | ||
| } | ||
|
|
||
| final override TranslatedElement getChildInternal(int id) { none() } | ||
|
|
||
| override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) { | ||
| tag = OnlyInstructionTag() and | ||
| result = this.getParent().getChildSuccessor(this, kind) | ||
| } | ||
|
|
||
| override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) } | ||
|
|
||
| override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) { | ||
| tag = OnlyInstructionTag() and | ||
| opcode instanceof Opcode::CopyValue and | ||
| resultType = getTypeForPRValue(expr.getType()) | ||
| } | ||
|
|
||
| override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) { | ||
| tag = OnlyInstructionTag() and | ||
| operandTag instanceof UnaryOperandTag and | ||
| result = | ||
| this.getEnclosingFunction().(TranslatedNonStaticDataMemberVarInit).getLoadThisInstruction() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * IR translation of an array access expression (e.g. `a[i]`). The array being accessed will either | ||
| * be a prvalue of pointer type (possibly due to an implicit array-to-pointer conversion), or a | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.