• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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
        • C
          • Syntax-for-tools
            • Formalized-subset
            • Mapping-to-language-definition
            • Input-files
            • Compilation-database
            • Printer
            • Output-files
            • Abstract-syntax-operations
            • Implementation-environments
            • Abstract-syntax
            • Concrete-syntax
            • Disambiguation
            • Validation
              • Validator
                • Valid-exprs/decls/stmts
                • Valid-stmt
                • Valid-expr
                • Valid-dirdeclor
                • Valid-binary
                • Valid-type-spec
                • Valid-transunit
                • Valid-stor-spec-list
                • Valid-prototype-args
                • Valid-fundef
                • Valid-unary
                • Valid-init-declor
                • Valid-stringlit-list
                • Valid-type-spec-list-residual
                • Valid-transunit-ensemble
                • Valid-cond
                • Valid-lookup-ord
                • Valid-c-char
                • Valid-funcall
                • Valid-iconst
                • Valid-add-ord-objfuns-file-scope
                • Valid-initer
                • Valid-declor
                • Valid-add-ord
                • Valid-arrsub
                  • Valid-update-ext
                  • Valid-ext-declon-list
                  • Valid-ext-declon
                  • Valid-univ-char-name
                  • Valid-memberp
                  • Valid-add-ord-file-scope
                  • Valid-var
                  • Valid-s-char
                  • Valid-decl-spec
                  • Valid-cconst
                  • Valid-cast
                  • Valid-sizeof/alignof
                  • Valid-stringlit
                  • Valid-spec/qual
                  • Valid-oct-escape
                  • Valid-get-fresh-uid
                  • Valid-param-declon
                  • Valid-struct-declon
                  • Valid-struct-declor
                  • Valid-has-internalp
                  • Valid-escape
                  • Valid-enum-const
                  • Valid-gensel
                  • Valid-const
                  • Valid-desiniter-list
                  • Valid-designor
                  • Valid-param-declor
                  • Valid-dec/oct/hex-const
                  • Valid-s-char-list
                  • Valid-decl-spec-list
                  • Valid-c-char-list
                  • Valid-member
                  • Valid-init-table
                  • Valid-lookup-ord-file-scope
                  • Valid-comp-stmt
                  • Valid-spec/qual-list
                  • Valid-lookup-ext
                  • Valid-designor-list
                  • Valid-fconst
                  • Valid-block-item
                  • Valid-struct-declor-list
                  • Valid-genassoc-list
                  • Valid-align-spec
                  • Valid-enumer
                  • Valid-declon
                  • Valid-simple-escape
                  • Valid-enum-spec
                  • Valid-dirabsdeclor
                  • Valid-declor-option
                  • Valid-pop-scope
                  • Valid-initer-option
                  • Valid-expr-list
                  • Valid-block-item-list
                  • Valid-absdeclor
                  • Valid-struct-declon-list
                  • Valid-push-scope
                  • Valid-label
                  • Valid-genassoc
                  • Valid-tyname
                  • Valid-struni-spec
                  • Valid-dirabsdeclor-option
                  • Valid-const-expr
                  • Valid-init-declor-list
                  • Valid-absdeclor-option
                  • Valid-param-declon-list
                  • Valid-desiniter
                  • Valid-const-expr-option
                  • Valid-table-num-scopes
                  • Valid-expr-option
                  • Valid-statassert
                  • Valid-enumer-list
                  • Valid-member-designor
                  • Valid-declon-list
                  • Valid-empty-scope
                • Validation-information
              • Gcc-builtins
              • Preprocessing
              • Parsing
            • Atc
            • Transformation-tools
            • Language
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Validator

    Valid-arrsub

    Validate an array subscripting expression, given the types of the two sub-expressions.

    Signature
    (valid-arrsub expr type-arg1 type-arg2) → (mv erp type)
    Arguments
    expr — Guard (exprp expr).
    type-arg1 — Guard (typep type-arg1).
    type-arg2 — Guard (typep type-arg2).
    Returns
    erp — Type (maybe-msgp erp).
    type — Type (typep type).

    After converting array types to pointer types, one sub-expression must have pointer type, and the other sub-expression must have integer type [C17:6.5.2.1/1]. The expression has the type referenced by the pointer type.

    There is no need to perform function-to-pointer conversion, because that would result in a pointer to function, which is disallowed, as it has to be a pointer to a complete object type [C17:6.5.2.1/1]. So by leaving function types as such, we automatically disallow them.

    Definitions and Theorems

    Function: valid-arrsub

    (defun valid-arrsub (expr type-arg1 type-arg2)
     (declare (xargs :guard (and (exprp expr)
                                 (typep type-arg1)
                                 (typep type-arg2))))
     (declare (xargs :guard (expr-case expr :arrsub)))
     (b* (((reterr) (irr-type))
          (type1 (type-apconvert type-arg1))
          (type2 (type-apconvert type-arg2))
          ((when (and (type-case type1 :pointer)
                      (or (type-integerp type2)
                          (type-case type2 :unknown))))
           (retok (type-pointer->to type1)))
          ((when (and (type-case type2 :pointer)
                      (or (type-integerp type1)
                          (type-case type1 :unknown))))
           (retok (type-pointer->to type2)))
          ((when (or (type-case type-arg1 :unknown)
                     (type-case type-arg2 :unknown)))
           (retok (type-unknown))))
      (retmsg$
       "In the array subscripting expression ~x0, ~
                  the first sub-expression has type ~x1, ~
                  and the second sub-expression has type ~x2."
       (expr-fix expr)
       (type-fix type-arg1)
       (type-fix type-arg2))))

    Theorem: maybe-msgp-of-valid-arrsub.erp

    (defthm maybe-msgp-of-valid-arrsub.erp
      (b* (((mv acl2::?erp ?type)
            (valid-arrsub expr type-arg1 type-arg2)))
        (maybe-msgp erp))
      :rule-classes :rewrite)

    Theorem: typep-of-valid-arrsub.type

    (defthm typep-of-valid-arrsub.type
      (b* (((mv acl2::?erp ?type)
            (valid-arrsub expr type-arg1 type-arg2)))
        (typep type))
      :rule-classes :rewrite)

    Theorem: valid-arrsub-of-expr-fix-expr

    (defthm valid-arrsub-of-expr-fix-expr
      (equal (valid-arrsub (expr-fix expr)
                           type-arg1 type-arg2)
             (valid-arrsub expr type-arg1 type-arg2)))

    Theorem: valid-arrsub-expr-equiv-congruence-on-expr

    (defthm valid-arrsub-expr-equiv-congruence-on-expr
      (implies (expr-equiv expr expr-equiv)
               (equal (valid-arrsub expr type-arg1 type-arg2)
                      (valid-arrsub expr-equiv type-arg1 type-arg2)))
      :rule-classes :congruence)

    Theorem: valid-arrsub-of-type-fix-type-arg1

    (defthm valid-arrsub-of-type-fix-type-arg1
      (equal (valid-arrsub expr (type-fix type-arg1)
                           type-arg2)
             (valid-arrsub expr type-arg1 type-arg2)))

    Theorem: valid-arrsub-type-equiv-congruence-on-type-arg1

    (defthm valid-arrsub-type-equiv-congruence-on-type-arg1
      (implies (type-equiv type-arg1 type-arg1-equiv)
               (equal (valid-arrsub expr type-arg1 type-arg2)
                      (valid-arrsub expr type-arg1-equiv type-arg2)))
      :rule-classes :congruence)

    Theorem: valid-arrsub-of-type-fix-type-arg2

    (defthm valid-arrsub-of-type-fix-type-arg2
      (equal (valid-arrsub expr type-arg1 (type-fix type-arg2))
             (valid-arrsub expr type-arg1 type-arg2)))

    Theorem: valid-arrsub-type-equiv-congruence-on-type-arg2

    (defthm valid-arrsub-type-equiv-congruence-on-type-arg2
      (implies (type-equiv type-arg2 type-arg2-equiv)
               (equal (valid-arrsub expr type-arg1 type-arg2)
                      (valid-arrsub expr type-arg1 type-arg2-equiv)))
      :rule-classes :congruence)