• 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-funcall

    Validate a function call expression, given the types of the sub-expressions.

    Signature
    (valid-funcall expr type-fun types-arg ienv) → (mv erp type)
    Arguments
    expr — Guard (exprp expr).
    type-fun — Guard (typep type-fun).
    types-arg — Guard (type-listp types-arg).
    ienv — Guard (ienvp ienv).
    Returns
    erp — Type (maybe-msgp erp).
    type — Type (typep type).

    After converting function types to pointer types, the first sub-expression must have pointer type [C17:6.5.2.2/1]; Furthermore, it must be a pointer to a function type.

    There is no need to perform array-to-pointer conversion, because array types cannot have function element types, but only (complete) object element types [C17:6.2.5/20]. Thus, the conversion could never result into a pointer to a function.

    When the function expression is a pointer to a function type which includes a prototype, we validate the arguments against the prototype parameter list [C17:6.5.2.2/2] (see valid-prototype-args). We return the function return type.

    Definitions and Theorems

    Function: valid-funcall

    (defun valid-funcall (expr type-fun types-arg ienv)
     (declare (xargs :guard (and (exprp expr)
                                 (typep type-fun)
                                 (type-listp types-arg)
                                 (ienvp ienv))))
     (declare
          (xargs :guard (and (expr-case expr :funcall)
                             (equal (len types-arg)
                                    (len (expr-funcall->args expr))))))
     (b*
      (((reterr) (irr-type))
       ((when (type-case type-fun :unknown))
        (retok (type-unknown)))
       (type (type-fpconvert type-fun))
       ((unless (type-case type :pointer))
        (retmsg$
         "In the function call expression ~x0, ~
                      the first sub-expression is expected to have a pointer type, ~
                      but it has type ~x1."
         (expr-fix expr)
         (type-fix type-fun)))
       (to-type (type-pointer->to type))
       ((when (type-case to-type :unknown))
        (retok (type-unknown)))
       ((unless (type-case to-type :function))
        (retmsg$
         "In the function call expression ~x0, ~
                      the first sub-expression is expected
                      to have a function pointer or unknown pointer type,
                      but it has type ~x1."
         (expr-fix expr)
         (type-fix type-fun)))
       (type-params (type-function->params to-type))
       ((erp)
        (type-params-case
             type-params
             :prototype
             (valid-prototype-args type-params.params
                                   (expr-funcall->args expr)
                                   types-arg type-params.ellipsis ienv)
             :otherwise (retok))
        :iferr (msg$ "Error in function call ~x0:~%~@1"
                     (expr-fix expr)
                     erp)))
      (retok (type-function->ret to-type))))

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

    (defthm maybe-msgp-of-valid-funcall.erp
      (b* (((mv acl2::?erp ?type)
            (valid-funcall expr type-fun types-arg ienv)))
        (maybe-msgp erp))
      :rule-classes :rewrite)

    Theorem: typep-of-valid-funcall.type

    (defthm typep-of-valid-funcall.type
      (b* (((mv acl2::?erp ?type)
            (valid-funcall expr type-fun types-arg ienv)))
        (typep type))
      :rule-classes :rewrite)

    Theorem: valid-funcall-of-expr-fix-expr

    (defthm valid-funcall-of-expr-fix-expr
      (equal (valid-funcall (expr-fix expr)
                            type-fun types-arg ienv)
             (valid-funcall expr type-fun types-arg ienv)))

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

    (defthm valid-funcall-expr-equiv-congruence-on-expr
      (implies
           (expr-equiv expr expr-equiv)
           (equal (valid-funcall expr type-fun types-arg ienv)
                  (valid-funcall expr-equiv type-fun types-arg ienv)))
      :rule-classes :congruence)

    Theorem: valid-funcall-of-type-fix-type-fun

    (defthm valid-funcall-of-type-fix-type-fun
      (equal (valid-funcall expr (type-fix type-fun)
                            types-arg ienv)
             (valid-funcall expr type-fun types-arg ienv)))

    Theorem: valid-funcall-type-equiv-congruence-on-type-fun

    (defthm valid-funcall-type-equiv-congruence-on-type-fun
      (implies
           (type-equiv type-fun type-fun-equiv)
           (equal (valid-funcall expr type-fun types-arg ienv)
                  (valid-funcall expr type-fun-equiv types-arg ienv)))
      :rule-classes :congruence)

    Theorem: valid-funcall-of-type-list-fix-types-arg

    (defthm valid-funcall-of-type-list-fix-types-arg
      (equal (valid-funcall expr type-fun (type-list-fix types-arg)
                            ienv)
             (valid-funcall expr type-fun types-arg ienv)))

    Theorem: valid-funcall-type-list-equiv-congruence-on-types-arg

    (defthm valid-funcall-type-list-equiv-congruence-on-types-arg
      (implies
           (type-list-equiv types-arg types-arg-equiv)
           (equal (valid-funcall expr type-fun types-arg ienv)
                  (valid-funcall expr type-fun types-arg-equiv ienv)))
      :rule-classes :congruence)

    Theorem: valid-funcall-of-ienv-fix-ienv

    (defthm valid-funcall-of-ienv-fix-ienv
      (equal (valid-funcall expr type-fun types-arg (ienv-fix ienv))
             (valid-funcall expr type-fun types-arg ienv)))

    Theorem: valid-funcall-ienv-equiv-congruence-on-ienv

    (defthm valid-funcall-ienv-equiv-congruence-on-ienv
      (implies
           (ienv-equiv ienv ienv-equiv)
           (equal (valid-funcall expr type-fun types-arg ienv)
                  (valid-funcall expr type-fun types-arg ienv-equiv)))
      :rule-classes :congruence)