Skip to content

Parsing of member bounds declarations. #23

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

Closed
secure-sw-dev-bot opened this issue Jan 16, 2022 · 2 comments
Closed

Parsing of member bounds declarations. #23

secure-sw-dev-bot opened this issue Jan 16, 2022 · 2 comments

Comments

@secure-sw-dev-bot
Copy link

This issue was copied from checkedc/checkedc-clang#23


This change adds parsing of member bounds declarations (issue #19). Member bounds
declarations use member bounds expressions, which can only use other
members of the structure. The changes include:

  • IR: no change is needed to represent member bounds expressions. Because
    clang handles C++, it already can represent members directly in
    the IR for expressions. Bounds expressions are a subclass of expressions.

    We need to attach bounds expressions to member declarations. We already
    have bounds expressions on function declarations and variable declarations,
    which have the same base class as member declarations. Instead of having
    a 3rd copy of the code, we factor the common code for representing bounds
    expressions and move it to the common base.

  • Parsing: we modify the parsing of member declarators that are followed
    by ':' to parse either a bounds expression or a constant-expression
    that is a bit-field size. We check whether the first token after the
    ':' is an identifier that is contextual keyword for bounds expressions.

    The parsing of bounds expressions is deferred until all members of the
    structure have been seen. This is so that member bounds expressions may
    refer to any member of the structure. Constant expressions for bitfield
    sizes continue to be eagerly parsed.

    The decision to just look for a bounds expression keyword can lead
    to several error messages from clang if there is a spelling
    error in a contextual keyword. Clang interprets the misspelled keyword
    as an implicit function declaration and issues unknown identifier errors
    for uses of members.

    For now, we'll live this because this specific case is a fairly
    low priority to address. The type for the identifier in the declarator
    hasn't been built yet at the time that we make the parsing decision.
    We could move that up or defer parsing of constant expressions. Either
    change is largely orthogonal to this change.

  • Semantic processing: member bounds expressions are restricted to accessing
    only members. We add a state flag to Sema that changes the lookup of C
    identifiers during expression parsing to look up identifiers in the
    member namespace instead of the ordinary namespace. The state flag is
    protected by an RAII class.

Testing:

  • Wrote new feature tests of parsing member bounds
    declaration. These will be checked in separately to the Checked C
    repo in parsing\member_bounds.c.
  • Passes existing clang test baseline.
@secure-sw-dev-bot
Copy link
Author

Comment from @msftclas:

Hi @dtarditi, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (David Tarditi). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@secure-sw-dev-bot
Copy link
Author

Comment from @reubeno:

This generally looks good to me--just had a few low-priority suggestions around the code and a few questions around the lifetime of cached tokens.

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

No branches or pull requests

1 participant