Skip to content

C++: Two IR fixes and a PrintAST workaround#1674

Merged
jbj merged 2 commits intogithub:masterfrom
dave-bartolomeo:dave/ExternDecls2
Aug 6, 2019
Merged

C++: Two IR fixes and a PrintAST workaround#1674
jbj merged 2 commits intogithub:masterfrom
dave-bartolomeo:dave/ExternDecls2

Conversation

@dave-bartolomeo
Copy link
Contributor

My original fix in #1661 fixed my minimal test case, but did not fix the original failure in a Linux snapshot. The real fix is to simply not create a TranslatedDeclarationEntry for an extern declaration, and have TranslatedDeclStmt skip any such declarations. I've added a regression test for that case (multiple extern declarations with same location in a macro expansion, with control flow between them). I did verify that it generates correct IR, and that it fixes all of the "use not dominated by definition" failures in Linux.

The underlying extractor bug, that caused the above issue also caused PrintAST to print garbage. I've worked around the bug in PrintAST.qll.

I've also fixed a bug in the control flow for try/catch, where there was missing flow from the CatchByType of the last handler of a try to the enclosing handler (or Unwind). Hat tip to @andreidiaconu1 for spotting this bug.

My original fix in github#1661 fixed my minimal test case, but did not fix the original failure in a Linux snapshot. The real fix is to simply not create a `TranslatedDeclarationEntry` for an extern declaration, and have `TranslatedDeclStmt` skip any such declarations. I've added a regression test for that case (multiple extern declarations with same location in a macro expansion, with control flow between them). I did verify that it generates correct IR, and that it fixes all of the "use not dominated by definition" failures in Linux.

The underlying extractor bug, that caused the above issue also caused PrintAST to print garbage. I've worked around the bug in PrintAST.qll.

I've also fixed a bug in the control flow for `try`/`catch`, where there was missing flow from the `CatchByType` of the last handler of a `try` to the enclosing handler (or `Unwind`). Hat tip to @andreidiaconu1 for spotting this bug.
@dave-bartolomeo dave-bartolomeo requested a review from a team as a code owner August 1, 2019 21:42
@dave-bartolomeo dave-bartolomeo changed the title C++: Two IR fixes C++: Two IR fixes and a PrintAST workaround Aug 1, 2019
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Reviewed all but PrintAST.qll

@dave-bartolomeo
Copy link
Contributor Author

@zlaski-semmle do the PrintAST changes look OK?

@zlaski-semmle
Copy link
Contributor

Alas, I'm insufficiently knowledgeable to review this.

@zlaski-semmle
Copy link
Contributor

Another question is whether the changes to PrintAST.qll are strictly a workaround for an extractor bug. If so, perhaps we can leave things as they are and simply wait until the extractor bug is fixed? What sort of printing "artifacts" did you run into?

@dave-bartolomeo
Copy link
Contributor Author

The extractor issue is unlikely to be fixed soon. My understanding is that it's not easy to efficiently compute the correct parent for this specific case given EDG's current AST representation. Until it's fixed, any PrintAST invocation that hits this code pattern produces nodes scattered everywhere, disconnected from parents, with multiple copies. This is because we produce a depth-first numbering of the complete tree, and when the tree is not really a tree but a DAG, our numbering algorithm produces multiple numbers for a single node. It was completely unusable when I tried it.

@dave-bartolomeo
Copy link
Contributor Author

Anybody in @Semmle/cpp available to review the PrintAST changes here?

Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

DeclarationEntry entry;
class DeclarationEntryNode extends BaseASTNode, TDeclarationEntryNode {
override DeclarationEntry ast;
DeclStmt declStmt;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the declStmt field used? I can't find a use.

@jbj jbj merged commit 4dfd4f1 into github:master Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants