-
Notifications
You must be signed in to change notification settings - Fork 22
Fix: Incomplete Call Graph Due to Early Return in makeAllCG Branch #105
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2023,6 +2023,12 @@ class Analyzer extends MemSpace { | |||||
| */ | ||||||
| executeCall(node: any, fclos: any, argvalues: any, state: any, scope: any): any { | ||||||
| if (Config.makeAllCG && fclos?.fdef?.type === 'FunctionDefinition' && this.ainfo?.callgraph?.nodes) { | ||||||
| const funcKey = `${fclos.fdef?.loc?.sourcefile}:${fclos.fdef?.loc?.start?.line}-${fclos.fdef?.loc?.end?.line}` | ||||||
|
|
||||||
| if (!this.ainfo.analyzedFunctionBodies) { | ||||||
| this.ainfo.analyzedFunctionBodies = new Set() | ||||||
| } | ||||||
|
Comment on lines
+2028
to
+2030
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. This check and initialization of |
||||||
|
|
||||||
| for (const callgraphnode of this.ainfo?.callgraph?.nodes.values()) { | ||||||
| if ( | ||||||
| callgraphnode.opts?.funcDef?.loc?.start?.line && | ||||||
|
|
@@ -2031,6 +2037,9 @@ class Analyzer extends MemSpace { | |||||
| callgraphnode.opts?.funcDef?.loc?.start?.line === fclos.fdef?.loc?.start?.line && | ||||||
| callgraphnode.opts?.funcDef?.loc?.end?.line === fclos.fdef?.loc?.end?.line | ||||||
| ) { | ||||||
| const alreadyAnalyzed = this.ainfo.analyzedFunctionBodies.has(funcKey) | ||||||
|
|
||||||
| // add call edge | ||||||
| this.checkerManager.checkAtFunctionCallBefore(this, scope, node, state, { | ||||||
| argvalues, | ||||||
| fclos, | ||||||
|
|
@@ -2041,12 +2050,18 @@ class Analyzer extends MemSpace { | |||||
| analyzer: this, | ||||||
| ainfo: this.ainfo, | ||||||
| }) | ||||||
| return SymbolValue({ | ||||||
| type: 'FunctionCall', | ||||||
| expression: fclos, | ||||||
| arguments: argvalues, | ||||||
| ast: node, | ||||||
| }) | ||||||
|
|
||||||
| if (alreadyAnalyzed) { | ||||||
| return SymbolValue({ | ||||||
| type: 'FunctionCall', | ||||||
| expression: fclos, | ||||||
| arguments: argvalues, | ||||||
| ast: node, | ||||||
| }) | ||||||
| } else { | ||||||
| this.ainfo.analyzedFunctionBodies.add(funcKey) | ||||||
| break | ||||||
|
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. Double call to
|
||||||
| } | ||||||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -2504,13 +2519,14 @@ class Analyzer extends MemSpace { | |||||
|
|
||||||
| if (logger.isTraceEnabled()) logger.trace(`\nprocessCall: function: ${this.formatScope(fdecl?.id?.name)}`) | ||||||
|
|
||||||
| // avoid infinite loops,the re-entry should only less than 3 | ||||||
| if ( | ||||||
| fdecl && | ||||||
| state.callstack.reduce((previousValue: any, currentValue: any) => { | ||||||
| return currentValue.fdef === fdecl ? previousValue + 1 : previousValue | ||||||
| }, 0) > 0 | ||||||
| ) { | ||||||
| // avoid infinite loops, the re-entry should only less than 3 | ||||||
|
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 comment is misleading. It states that re-entry should be less than 3, but the logic (
Suggested change
|
||||||
| const recursionCount = fdecl | ||||||
| ? state.callstack.reduce((previousValue: any, currentValue: any) => { | ||||||
| return currentValue.fdef === fdecl ? previousValue + 1 : previousValue | ||||||
| }, 0) | ||||||
| : 0 | ||||||
|
|
||||||
| if (fdecl && recursionCount > 0) { | ||||||
| return SymbolValue({ | ||||||
| type: 'FunctionCall', | ||||||
| expression: fclos, | ||||||
|
|
||||||


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.
fclosNamemay be object causingstartsWithTypeErrorMedium Severity
fclosNameis assigned viafclos?.name || fclos?.id || fclos?.sid || ''but these properties can be objects, not strings. TheprettyPrintmethod in the same file explicitly handles non-stringfclos.idandfclos.sid. If any is an object,fclosName.startsWith('...')inshouldSkipCallthrows a TypeError.Additional Locations (1)
src/checker/callgraph/callgraph-checker.ts#L98-L100