• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
        • Syntax-for-tools
        • Atc
        • Language
          • Abstract-syntax
          • Integer-ranges
          • Implementation-environments
          • Dynamic-semantics
          • Static-semantics
            • Check-stmt
            • Check-cond
            • Check-binary-pure
            • Var-table-add-var
            • Check-unary
            • Check-obj-declon
            • Fun-table-add-fun
            • Check-fundef
            • Fun-sinfo
            • Check-expr-asg
            • Check-expr-call
            • Check-arrsub
              • Uaconvert-types
              • Apconvert-type-list
              • Check-initer
              • Adjust-type-list
              • Types+vartab
              • Promote-type
              • Check-tag-declon
              • Check-expr-call-or-asg
              • Check-ext-declon
              • Check-param-declon
              • Check-member
              • Check-expr-pure
              • Init-type-matchp
              • Check-obj-adeclor
              • Check-memberp
              • Check-expr-call-or-pure
              • Check-cast
              • Check-struct-declon-list
              • Check-fun-declor
              • Expr-type
              • Check-ext-declon-list
              • Check-transunit
              • Check-fun-declon
              • Var-defstatus
              • Struct-member-lookup
              • Preprocess
              • Wellformed
              • Check-tyspecseq
              • Check-param-declon-list
              • Check-iconst
              • Check-expr-pure-list
              • Var-sinfo-option
              • Fun-sinfo-option
              • Var-scope-all-definedp
              • Funtab+vartab+tagenv
              • Var-sinfo
              • Var-table-lookup
              • Apconvert-type
              • Var-table
              • Check-tyname
              • Types+vartab-result
              • Funtab+vartab+tagenv-result
              • Fun-table-lookup
              • Wellformed-result
              • Var-table-add-block
              • Var-table-scope
              • Var-table-result
              • Fun-table-result
              • Expr-type-result
              • Adjust-type
              • Check-fileset
              • Var-table-all-definedp
              • Check-const
              • Fun-table-all-definedp
              • Check-ident
              • Fun-table
              • Var-table-init
              • Fun-table-init
            • Grammar
            • Integer-formats
            • Types
            • Portable-ascii-identifiers
            • Values
            • Integer-operations
            • Computation-states
            • Object-designators
            • Operations
            • Errors
            • Tag-environments
            • Function-environments
            • Character-sets
            • Flexible-array-member-removal
            • Arithmetic-operations
            • Pointer-operations
            • Bytes
            • Keywords
            • Real-operations
            • Array-operations
            • Scalar-operations
            • Structure-operations
          • Representation
          • Transformation-tools
          • Insertion-sort
          • Pack
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Static-semantics

    Check-arrsub

    Check an array subscripting expression [C17:6.5.2.1].

    Signature
    (check-arrsub arr-expr arr-etype sub-expr sub-etype) → etype
    Arguments
    arr-expr — Guard (exprp arr-expr).
    arr-etype — Guard (expr-typep arr-etype).
    sub-expr — Guard (exprp sub-expr).
    sub-etype — Guard (expr-typep sub-etype).
    Returns
    etype — Type (expr-type-resultp etype).

    We check arr-etype and sub-etype; arr-expr and sub-expr are just used for errors.

    We do lvalue conversion for both operands, via expr-type->type. According to [C17:6.3.2/2], we should not do this if an operand has an array type; however, according to [C17:6.3.2/3], we should convert the array to a pointer (which we do via apconvert-type), and thus in the end the result is the same: we have a pointer type that does not denote an lvalue, if the operand is an array. If an operand is an integer, apconvert-type has no effect.

    The first expression must have a pointer type [C17:6.5.2.1/1]. The second expression must have an integer type [C17:6.5.2.1/1]. The type of the array subscripting expression is the type referenced by the pointer. An array subscripting expression is always an lvalue.

    For now we do not allow the roles of the expressions to be swapped, i.e. that the second expression is a pointer and the first one an integer; note the symmetry in [C17:6.5.2.1/2].

    Definitions and Theorems

    Function: check-arrsub

    (defun check-arrsub (arr-expr arr-etype sub-expr sub-etype)
      (declare (xargs :guard (and (exprp arr-expr)
                                  (expr-typep arr-etype)
                                  (exprp sub-expr)
                                  (expr-typep sub-etype))))
      (let ((__function__ 'check-arrsub))
        (declare (ignorable __function__))
        (b* ((arr-type (apconvert-type (expr-type->type arr-etype)))
             (sub-type (apconvert-type (expr-type->type sub-etype)))
             ((unless (type-case arr-type :pointer))
              (reserrf (list :array-mistype (expr-fix arr-expr)
                             :required :pointer
                             :supplied (type-fix arr-type))))
             ((unless (type-integerp sub-type))
              (reserrf (list :subscript-mistype (expr-fix sub-expr)
                             :required :integer
                             :supplied (type-fix sub-type)))))
          (make-expr-type :type (type-pointer->to arr-type)
                          :lvalue t))))

    Theorem: expr-type-resultp-of-check-arrsub

    (defthm expr-type-resultp-of-check-arrsub
      (b* ((etype (check-arrsub arr-expr arr-etype sub-expr sub-etype)))
        (expr-type-resultp etype))
      :rule-classes :rewrite)

    Theorem: check-arrsub-of-expr-fix-arr-expr

    (defthm check-arrsub-of-expr-fix-arr-expr
      (equal (check-arrsub (expr-fix arr-expr)
                           arr-etype sub-expr sub-etype)
             (check-arrsub arr-expr arr-etype sub-expr sub-etype)))

    Theorem: check-arrsub-expr-equiv-congruence-on-arr-expr

    (defthm check-arrsub-expr-equiv-congruence-on-arr-expr
      (implies
           (expr-equiv arr-expr arr-expr-equiv)
           (equal (check-arrsub arr-expr arr-etype sub-expr sub-etype)
                  (check-arrsub arr-expr-equiv
                                arr-etype sub-expr sub-etype)))
      :rule-classes :congruence)

    Theorem: check-arrsub-of-expr-type-fix-arr-etype

    (defthm check-arrsub-of-expr-type-fix-arr-etype
      (equal (check-arrsub arr-expr (expr-type-fix arr-etype)
                           sub-expr sub-etype)
             (check-arrsub arr-expr arr-etype sub-expr sub-etype)))

    Theorem: check-arrsub-expr-type-equiv-congruence-on-arr-etype

    (defthm check-arrsub-expr-type-equiv-congruence-on-arr-etype
      (implies
           (expr-type-equiv arr-etype arr-etype-equiv)
           (equal (check-arrsub arr-expr arr-etype sub-expr sub-etype)
                  (check-arrsub arr-expr
                                arr-etype-equiv sub-expr sub-etype)))
      :rule-classes :congruence)

    Theorem: check-arrsub-of-expr-fix-sub-expr

    (defthm check-arrsub-of-expr-fix-sub-expr
      (equal (check-arrsub arr-expr arr-etype (expr-fix sub-expr)
                           sub-etype)
             (check-arrsub arr-expr arr-etype sub-expr sub-etype)))

    Theorem: check-arrsub-expr-equiv-congruence-on-sub-expr

    (defthm check-arrsub-expr-equiv-congruence-on-sub-expr
      (implies
           (expr-equiv sub-expr sub-expr-equiv)
           (equal (check-arrsub arr-expr arr-etype sub-expr sub-etype)
                  (check-arrsub arr-expr
                                arr-etype sub-expr-equiv sub-etype)))
      :rule-classes :congruence)

    Theorem: check-arrsub-of-expr-type-fix-sub-etype

    (defthm check-arrsub-of-expr-type-fix-sub-etype
      (equal (check-arrsub arr-expr arr-etype
                           sub-expr (expr-type-fix sub-etype))
             (check-arrsub arr-expr arr-etype sub-expr sub-etype)))

    Theorem: check-arrsub-expr-type-equiv-congruence-on-sub-etype

    (defthm check-arrsub-expr-type-equiv-congruence-on-sub-etype
      (implies
           (expr-type-equiv sub-etype sub-etype-equiv)
           (equal (check-arrsub arr-expr arr-etype sub-expr sub-etype)
                  (check-arrsub arr-expr
                                arr-etype sub-expr sub-etype-equiv)))
      :rule-classes :congruence)