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

    Validate a unary expression, given the type of the sub-expression.

    Signature
    (valid-unary expr op type-arg ienv) → (mv erp type)
    Arguments
    expr — Guard (exprp expr).
    op — Guard (unopp op).
    type-arg — Guard (typep type-arg).
    ienv — Guard (ienvp ienv).
    Returns
    type — Type (typep type).

    The & operator requires an lvalue of any type as operand [C17:6.5.3.2/1] [C17:6.5.3.2/3], but we are not yet distinguishing lvalues from non-lvalues, so we allow any type of operand, and we return the (one) pointer type.

    The * unary operator requires an operand of a pointer type [C17:6.5.3.2/2], after array-to-pointer and function-to-pointer conversions; as always, we also need to allow the unknown type. Since we only have one type for pointers for now, the resulting type is unknown.

    The + and - unary operators require an operand of an arithmetic type [C17:6.5.3.3/1], and the result has the promoted type [C17:6.5.3.3/2]. There is no need for array-to-pointer and function-to-pointer conversions, because they never result in arithmetic types.

    The ~ operator requires an operand of an integer type [C17:6.5.3.3/1], and the result has the promoted type [C17:.6.5.3.3/4]. There is no need for array-to-pointer and function-to-pointer conversions, because they never result in arithmetic types.

    The ! operator requires an operand of a scalar type [C17:6.5.3.3/1], and result is always signed int [C17:6.5.3.3/5]. Since pointers may be involved, we perform array-to-pointer and function-to-pointer conversions.

    The sizeof operator applied to an expression requires a non-function complete type [C17:6.5.3.4/1]. In our current approximate type system, we just exclude function types, but we do not have a notion of complete types yet. The result has type size_t [C17:6.5.3.4/5], whose definition is implementation-defined, so for now we just return the unknown type; we will need to extend implementation environments with information about the definition of size_t.

    The ++ pre-increment and -- pre-decrement operators require a real or pointer operand [C17:6.5.3.1/1]. Since these expressions are equivalent to assignments [C17:6.5.3.1/2] [C17:6.5.3.1/3], the type of the result must be the type of the operand. We do not perform array-to-pointer or function-to-pointer conversions, because those result in pointers, not lvalues as required [C17:6.5.3.1/1].

    The ++ post-increment and -- post-decrement operators require a real or pointer operand [C17:6.5.2.4/1]. The type of the result is the same as the operand [C17:6.5.2.4/2] [C17:6.5.2.4/3]. We do not perform array-to-pointer or function-to-pointer conversions, because those result in pointers, not lvalues as required [C17:6.5.2.4/1].

    Definitions and Theorems

    Function: valid-unary

    (defun valid-unary (expr op type-arg ienv)
     (declare (xargs :guard (and (exprp expr)
                                 (unopp op)
                                 (typep type-arg)
                                 (ienvp ienv))))
     (declare (xargs :guard (expr-case expr :unary)))
     (let ((__function__ 'valid-unary))
      (declare (ignorable __function__))
      (b*
       (((reterr) (irr-type))
        ((when (type-case type-arg :unknown))
         (retok (type-unknown)))
        (msg
         (msg
          "In the unary expression ~x0, ~
                      the sub-expression has type ~x1."
          (expr-fix expr)
          (type-fix type-arg))))
       (case (unop-kind op)
         (:address (retok (type-pointer)))
         (:indir (b* ((type (type-fpconvert (type-apconvert type-arg)))
                      ((unless (type-case type :pointer))
                       (reterr msg)))
                   (retok (type-unknown))))
         ((:plus :minus)
          (b* (((unless (type-arithmeticp type-arg))
                (reterr msg)))
            (retok (type-promote type-arg ienv))))
         (:bitnot (b* (((unless (type-integerp type-arg))
                        (reterr msg)))
                    (retok (type-promote type-arg ienv))))
         (:lognot (b* ((type (type-fpconvert (type-apconvert type-arg)))
                       ((unless (type-scalarp type))
                        (reterr msg)))
                    (retok (type-sint))))
         ((:preinc :predec :postinc :postdec)
          (b* (((unless (or (type-realp type-arg)
                            (type-case type-arg :pointer)))
                (reterr msg)))
            (retok (type-fix type-arg))))
         (:sizeof (b* (((when (type-case type-arg :function))
                        (reterr msg)))
                    (retok (type-unknown))))
         (t (prog2$ (impossible) (reterr t)))))))

    Theorem: typep-of-valid-unary.type

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

    Theorem: valid-unary-of-expr-fix-expr

    (defthm valid-unary-of-expr-fix-expr
      (equal (valid-unary (expr-fix expr)
                          op type-arg ienv)
             (valid-unary expr op type-arg ienv)))

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

    (defthm valid-unary-expr-equiv-congruence-on-expr
      (implies (expr-equiv expr expr-equiv)
               (equal (valid-unary expr op type-arg ienv)
                      (valid-unary expr-equiv op type-arg ienv)))
      :rule-classes :congruence)

    Theorem: valid-unary-of-unop-fix-op

    (defthm valid-unary-of-unop-fix-op
      (equal (valid-unary expr (unop-fix op)
                          type-arg ienv)
             (valid-unary expr op type-arg ienv)))

    Theorem: valid-unary-unop-equiv-congruence-on-op

    (defthm valid-unary-unop-equiv-congruence-on-op
      (implies (unop-equiv op op-equiv)
               (equal (valid-unary expr op type-arg ienv)
                      (valid-unary expr op-equiv type-arg ienv)))
      :rule-classes :congruence)

    Theorem: valid-unary-of-type-fix-type-arg

    (defthm valid-unary-of-type-fix-type-arg
      (equal (valid-unary expr op (type-fix type-arg)
                          ienv)
             (valid-unary expr op type-arg ienv)))

    Theorem: valid-unary-type-equiv-congruence-on-type-arg

    (defthm valid-unary-type-equiv-congruence-on-type-arg
      (implies (type-equiv type-arg type-arg-equiv)
               (equal (valid-unary expr op type-arg ienv)
                      (valid-unary expr op type-arg-equiv ienv)))
      :rule-classes :congruence)

    Theorem: valid-unary-of-ienv-fix-ienv

    (defthm valid-unary-of-ienv-fix-ienv
      (equal (valid-unary expr op type-arg (ienv-fix ienv))
             (valid-unary expr op type-arg ienv)))

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

    (defthm valid-unary-ienv-equiv-congruence-on-ienv
      (implies (ienv-equiv ienv ienv-equiv)
               (equal (valid-unary expr op type-arg ienv)
                      (valid-unary expr op type-arg ienv-equiv)))
      :rule-classes :congruence)