Skip to content

Fix CodeGen assert failure for bounds-safe interfaces #869

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

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

kkjeer
Copy link
Contributor

@kkjeer kkjeer commented Jul 6, 2020

Fixes #861

This PR fixes a type-related assert that failed during code generation. The assertion was that the subexpression of an LValueToRValue cast had the same unqualified type as the destination type. However, this failed for cases involving bounds-safe interfaces. For example:

_Checked unsigned f(const unsigned char *cp : count(1))
{
    return cp[0];
}

Since cp has a bounds-safe interface type of _Array_ptr<unsigned char>, there is an implicit cast (_Array_ptr<const unsigned char>)cp in the subexpression of the cast LValueToRValue((_Array_ptr<const unsigned char>)cp). The destination type of the LValueToRValue cast is unsigned char *. This caused the CodeGen assert hasSameUnqualifiedType(_Array_ptr<const unsigned char>, unsigned char *) to fail.

This PR introduces a new method hasSameUnqualifiedUncheckedType which returns true if two types are the same, ignoring qualifiers and the checkedness of any pointer types. hasSameUnqualifiedUncheckedType(_Array_ptr<const unsigned char>, unsigned char *) returns true.

Testing:

  • Passed manual testing on Windows.
  • Passed automated testing on Windows/Linux.

@kkjeer kkjeer requested review from dtarditi and mgrang July 6, 2020 17:26
Copy link

@mgrang mgrang left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

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

LGTM also.

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.

Assertion failed in CodeGen
3 participants