• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
            • Disambiguator
            • Abstract-syntax
            • Parser
            • Validator
              • Valid-exprs/decls/stmts
              • Valid-stmt
                • Valid-expr
                • Valid-dirdeclor
                • Valid-type-spec
                • Valid-transunit
                • Valid-stor-spec-list
                • Valid-binary
                • Valid-unary
                • Valid-initdeclor
                • Valid-fundef
                • Valid-type-spec-list-residual
                • Valid-cond
                • Valid-lookup-ord
                • Valid-transunit-ensemble
                • Valid-declor
                • Valid-iconst
                • Valid-initer
                • Valid-c-char
                • Valid-stringlit-list
                • Valid-funcall
                • Valid-add-ord
                • Valid-arrsub
                • Valid-univ-char-name
                • Valid-extdecl
                • Valid-extdecl-list
                • Valid-cast
                • Valid-add-ord-file-scope
                • Valid-spec/qual
                • Valid-sizeof/alignof
                • Valid-memberp
                • Valid-decl-spec
                • Valid-var
                • Valid-param-declon
                • Valid-oct-escape
                • Valid-structdeclor
                • Valid-structdecl
                • Valid-designor
                • Valid-escape
                • Valid-enum-const
                • Valid-cconst
                • Valid-s-char
                • Valid-dec/oct/hex-const
                • Valid-const
                • Valid-gensel
                • Valid-decl-spec-list
                • Valid-lookup-ord-file-scope
                • Valid-member
                • Valid-param-declor
                • Valid-spec/qual-list
                • Valid-fconst
                • Valid-stringlit
                • Valid-s-char-list
                • Valid-c-char-list
                • Valid-block-item
                • Valid-structdeclor-list
                • Valid-simple-escape
                • Valid-align-spec
                • Valid-enumer
                • Valid-dirabsdeclor
                • Valid-decl
                • Valid-pop-scope
                • Valid-enumspec
                • Valid-declor-option
                • Valid-push-scope
                • Valid-initer-option
                • Valid-block-item-list
                • Valid-absdeclor
                • Valid-label
                • Valid-genassoc
                • Valid-tyname
                • Valid-strunispec
                • Valid-structdecl-list
                • Valid-genassoc-list
                • Valid-dirabsdeclor-option
                • Valid-designor-list
                • Valid-const-expr
                • Valid-initdeclor-list
                • Valid-desiniter-list
                • Valid-absdeclor-option
                • Valid-table-num-scopes
                • Valid-expr-list
                • Valid-param-declon-list
                • Valid-desiniter
                • Valid-const-expr-option
                • Valid-expr-option
                • Valid-statassert
                • Valid-enumer-list
                • Valid-init-table
                • Valid-empty-scope
                • Valid-member-designor
                • Valid-decl-list
              • Printer
              • Formalized-subset
              • Mapping-to-language-definition
              • Input-files
              • Defpred
              • Output-files
              • Abstract-syntax-operations
              • Validation-information
              • Implementation-environments
              • Concrete-syntax
              • Unambiguity
              • Ascii-identifiers
              • Preprocessing
              • Abstraction-mapping
            • Atc
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Validator
    • Valid-exprs/decls/stmts

    Valid-stmt

    Validate a statement.

    Signature
    (valid-stmt stmt table ienv) 
      → 
    (mv erp new-stmt return-types last-expr-type? new-table)
    Arguments
    stmt — Guard (stmtp stmt).
    table — Guard (valid-tablep table).
    ienv — Guard (ienvp ienv).
    Returns
    new-stmt — Type (stmtp new-stmt).
    return-types — Type (type-setp return-types).
    last-expr-type? — Type (type-optionp last-expr-type?).
    new-table — Type (valid-tablep new-table).

    If validation is successful, we return, besides an updated validation table, also two pieces of type information.

    The first piece is the set of types returned by the statement, via return statements, with or without expressions. This is a set because a statement may contain multiple return sub-statements. A return statement with an expression contributes the type of the expression to the set; a return statement without an expression contributes the type void to the set.

    The second piece of information is as follows. If the statement is either a (possibly labeled) expression statement, or is a (possibly labeled) compound one whose last block item is an expression statement, the second piece of information is the type of that expression. If the statement is not an expression or compound, or it is compound but does not end in an expression statement (including the case in which the compound statement has no block items), the second piece of information is nil. The reason for having this second piece of information is to support the validation of https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html.

    To validate a labeled statement, we validate its label, and then the enclosed statement. We return the union of the return types, and the optional type from the statement. For now we do not check the requirements in [C17:6.8.1/2] and [C17:6.8.1/3].

    To validate a compound statement, we push a new scope for the block, and we validate the list of block items. We pop the scope and we return the same results coming from the validation of the block items.

    To validate an expression statement, we validate the expression if present, and return its type as the second result; this is nil if there is no expression. The return types are the same as the ones of the expression.

    A selection statement and its sub-statements are blocks [C17:6.8.4/3], so we push and pop scopes accordingly. We check that the test of if has scalar type [C17:6.8.4.1/1] and that the target of switch has integer type [C17:6.8.4.2/1]. No type is returned as the last-expr-type? result, because a selection statement is not an expression statement (see criterion above for that result of this validation function).

    An iteration statement and its sub-statements are blocks [C17:6.8.5/5], so we push and pop scopes accordingly. We check that the test expression has scalar type. No type is returned as the last-expr-type? result, because an iteraion statement is not an expression statement (see criterion above for that result of this validation function). For now we do not enforce that the declaration in a for only uses the storage class specifiers auto and register.

    For now we do not check constraints on the label of a goto [C17:6.8.6.1/1], the occurrence of continue [C17:6.8.6.2/2], and the occurrence of break [C17:6.8.6.3/1].

    A return statement explicitly adds a type to the return types, either the type of the expression, or void is there is no expression. We check the constraints on occurrences [C17:6.8.6.4/1] in the validation function for function definitions.

    For now we do not check any constraints on assembler statements.