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

InitializerListExpression cannot be casted to ConstructExpression #1890

Open
peckto opened this issue Dec 9, 2024 · 0 comments
Open

InitializerListExpression cannot be casted to ConstructExpression #1890

peckto opened this issue Dec 9, 2024 · 0 comments
Assignees
Labels
bug Something isn't working cxx Related to C/C++ language parsing

Comments

@peckto
Copy link
Collaborator

peckto commented Dec 9, 2024

Stack trace

java.util.concurrent.ExecutionException: java.lang.ClassCastException: class de.fraunhofer.aisec.cpg.graph.statements.expressions.InitializerListExpression cannot be cast to class de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.InitializerListExpression and de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression are in unnamed module of loader 'app')
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at de.fraunhofer.aisec.cpg_vis_neo4j.Application.call(Application.kt:614)
	at de.fraunhofer.aisec.cpg_vis_neo4j.Application.call(Application.kt:88)
	at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
	at picocli.CommandLine.access$1500(CommandLine.java:148)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
	at picocli.CommandLine.execute(CommandLine.java:2170)
	at de.fraunhofer.aisec.cpg_vis_neo4j.ApplicationKt.main(Application.kt:655)
Caused by: java.lang.ClassCastException: class de.fraunhofer.aisec.cpg.graph.statements.expressions.InitializerListExpression cannot be cast to class de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.InitializerListExpression and de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression are in unnamed module of loader 'app')
	at de.fraunhofer.aisec.cpg.frontends.cxx.ExpressionHandler.handleNewExpression(ExpressionHandler.kt:266)
	at de.fraunhofer.aisec.cpg.frontends.cxx.ExpressionHandler.handleNode(ExpressionHandler.kt:81)
	at de.fraunhofer.aisec.cpg.frontends.cxx.ExpressionHandler.handleNode(ExpressionHandler.kt:61)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.InitializerHandler.handleEqualsInitializer(InitializerHandler.kt:93)
	at de.fraunhofer.aisec.cpg.frontends.cxx.InitializerHandler.handleNode(InitializerHandler.kt:48)
	at de.fraunhofer.aisec.cpg.frontends.cxx.InitializerHandler.handleNode(InitializerHandler.kt:43)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleSimpleDeclaration(DeclarationHandler.kt:493)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleNode(DeclarationHandler.kt:67)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleNode(DeclarationHandler.kt:62)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleDeclarationStatement(StatementHandler.kt:302)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleNode(StatementHandler.kt:53)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleNode(StatementHandler.kt:46)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleCompoundStatement(StatementHandler.kt:329)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleNode(StatementHandler.kt:51)
	at de.fraunhofer.aisec.cpg.frontends.cxx.StatementHandler.handleNode(StatementHandler.kt:46)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleFunctionDefinition(DeclarationHandler.kt:207)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleNode(DeclarationHandler.kt:68)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleNode(DeclarationHandler.kt:62)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXHandler.handle(CXXHandler.kt:58)
	at de.fraunhofer.aisec.cpg.frontends.cxx.DeclarationHandler.handleTranslationUnit(DeclarationHandler.kt:732)
	at de.fraunhofer.aisec.cpg.frontends.cxx.CXXLanguageFrontend.parse(CXXLanguageFrontend.kt:270)
	at de.fraunhofer.aisec.cpg.TranslationManager.parse(TranslationManager.kt:397)
	at de.fraunhofer.aisec.cpg.TranslationManager.parseSequentially(TranslationManager.kt:350)
	at de.fraunhofer.aisec.cpg.TranslationManager.runFrontends(TranslationManager.kt:250)
	at de.fraunhofer.aisec.cpg.TranslationManager.analyzeNonAsync(TranslationManager.kt:88)
	at de.fraunhofer.aisec.cpg.TranslationManager.analyze$lambda$0(TranslationManager.kt:70)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Unexpected behavior

When handling the new expression of a template class, the InitializerListExpression is casted to an ConstructExpression, which is not possible, as both classes are siblings.

When I'm thinking about this, I'm wondering why this error is not spotted by the linter?

Code of interest

poc:

template <typename T>
struct A
{
        int i;
};

int  main() {
        A<int> a{1};  // OK
        A<int> *p = new A<int>{1};  // Fail

        return 0;
}

ExpressionHandler:

// we also need to "forward" our template parameters (if we have any) to the construct
// expression since the construct expression will do the actual template instantiation
if (newExpression.templateParameters.isNotEmpty() == true) {
addImplicitTemplateParametersToCall(
newExpression.templateParameters,
initializer as ConstructExpression
)
}

Extensions to the library, e.g. added or changed LanguageFrontends or Passes

No

Changes to the configuration

No

@peckto peckto added bug Something isn't working cxx Related to C/C++ language parsing labels Dec 9, 2024
@peckto peckto self-assigned this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cxx Related to C/C++ language parsing
Projects
None yet
Development

No branches or pull requests

1 participant