Skip to content

Fix internal assert caused by visiting AST nodes twice.#408

Merged
dtarditi merged 2 commits into
masterfrom
checkedc-issue221
Nov 3, 2017
Merged

Fix internal assert caused by visiting AST nodes twice.#408
dtarditi merged 2 commits into
masterfrom
checkedc-issue221

Conversation

@dtarditi

@dtarditi dtarditi commented Nov 3, 2017

Copy link
Copy Markdown
Member

This fixes a compiler crash reported in checkedc/checkedc#221. The checking of bounds information was failling an assertion that bounds are only set once for cast expression nodes. I tracked the problem to an issue in RecursiveASTVisitor.h. It turns out that nodes in initializer lists are visited multiple times if they appear in both semantic and syntactic forms of an initializer list. The comment in RecursiveASTVisitor.h about AST nodes being visited exactly once isn't quite accurate.

The fix is to borrow an approach used in lib\index\IndexBody.cpp and visit only one form. In our case, we want to visit the semantic form. We'll eventually have more complex checking that ensures that structs are initialized to satisfy their member bounds invariants, and we'll need to use the semantic form for that.

Testing:

  • Added a regression test case to the test\CheckedC directory.
  • Passed clang regression tests on Linux. Additional automated testing progress.

This fixes a compiler crash reported in
checkedc/checkedc#221.  The checking of bounds
information was failling an assertion that bounds are only set once for cast
expression nodes.  I tracked the problem to an issue in RecursiveASTVisitor.h.
It turns out nodes in initializer lists are visited multiple times if they
appear in both semantic and syntactic forms of an initializer list.
The comment in RecursiveASTVisitor.h about AST nodes being visited exactly
once isn't quite accurate.

The fix is to borrow an approach used in lib\index\IndexBody.cpp and visit only
one form.  In our case, we want to visit the semantic form. We'll eventually
have more complex checking that ensures that structs are initialized to satisfy
their member bounds invariants, and we'll need to use the semantic form
for that.

Testing:
- Added a regression test case to the test\CheckedC directory.
@dtarditi dtarditi requested review from awruef and lenary November 3, 2017 01:28
@mwhicks1

mwhicks1 commented Nov 3, 2017

Copy link
Copy Markdown
Contributor

This works on the vsftpd code that prompted my bug report.

@awruef awruef left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Owch, I should double check if the converter has the same problem. Looks good to me.

@dtarditi dtarditi merged commit 0cc23b6 into master Nov 3, 2017

@lenary lenary left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@dtarditi dtarditi deleted the checkedc-issue221 branch November 8, 2017 19:49
dopelsunce pushed a commit to dopelsunce/checkedc-clang that referenced this pull request Sep 28, 2020
sulekhark pushed a commit that referenced this pull request Jul 8, 2021
* Fix #373
* Use a single constraint variable to represent each typedef
* Fix rewriting for array typedefs
* Fix rewriting for function typedefs

Co-authored-by: Matt McCutchen (Correct Computation) <matt@correctcomputation.com>
Co-authored-by: John Kastner <john@correctcomputation.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants