Skip to content

Parsing of member bounds declarations. #23

Closed
@secure-sw-dev-bot

Description

@secure-sw-dev-bot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions