• 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
              • Validation-information
                • Abstract-syntax-annop
                • Types
                  • Type-compatiblep
                  • Type-uaconvert-signed-unsigned
                  • Type-uaconvert
                  • Type-integer-promote
                    • Type-params-compatiblep
                    • Type-option
                    • Type-formalp
                    • Ldm-type
                    • Make-pointers-to
                    • Type-list-default-arg-promote
                    • Type-uaconvert-unsigned
                    • Type-uaconvert-signed
                    • Type-default-arg-promote
                    • Type-default-arg-promotedp
                    • Type-params-composite
                    • Type-integer-promotedp
                    • Ldm-type-option-set
                    • Type-unsigned-integerp
                    • Type-standard-unsigned-integerp
                    • Type-signed-integerp
                    • Type-to-value-kind
                    • Type-standard-signed-integerp
                    • Ildm-type
                    • Type-arithmeticp
                    • Ldm-type-set
                    • Ldm-type-option
                    • Type-standard-integerp
                    • Type-option-set-formalp
                    • Type-real-floatingp
                    • Type-option-formalp
                    • Type-integerp
                    • Type-characterp
                    • Type-basicp
                    • Type-aggregatep
                    • Type-scalarp
                    • Type-realp
                    • Type-fpconvert
                    • Type-floatingp
                    • Type-complexp
                    • Type-set-formalp
                    • Type-apconvert
                    • Type-composite
                    • Ident-type-map
                    • Type-set
                    • Type-option-type-alist
                    • Type-option-set
                    • Type-list-compatiblep
                    • Irr-type-params
                    • Irr-type
                    • Type-list-composite
                    • Type/type-params/type-list
                  • Abstract-syntax-anno-additional-theroems
                  • Valid-ext-info
                  • Valid-table
                  • Valid-ord-info
                  • Uid
                  • Stmts-types
                  • Lifetime
                  • Init-declor-info
                  • Fundef-types
                  • Expr-type
                  • Valid-defstatus
                  • Var-info
                  • Valid-ord-info-option
                  • Valid-ext-info-option
                  • Uid-option
                  • Linkage-option
                  • Linkage
                  • Lifetime-option
                  • Valid-table-option
                  • Iconst-info
                  • Param-declor-nonabstract-info
                  • Fundef-info
                  • Expr-null-pointer-constp
                  • Valid-scope
                  • Const-expr-null-pointer-constp
                  • Expr-string-info
                  • Expr-funcall-info
                  • Expr-arrsub-info
                  • Tyname-info
                  • Transunit-info
                  • Expr-unary-info
                  • Expr-const-info
                  • Expr-binary-info
                  • Stmt-types
                  • Block-item-list-types
                  • Initer-type
                  • Valid-ord-scope
                  • Uid-increment
                  • Uid-equal
                  • Coerce-var-info
                  • Valid-externals
                  • Irr-var-info
                  • Valid-scope-list
                  • Irr-valid-table
                  • Irr-lifetime
                  • Irr-uid
                  • Irr-linkage
                  • Block-item-types
                  • Comp-stmt-types
              • 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
    • Types

    Type-integer-promote

    Perform integer promotions on an arithmetic type [C17:6.3.1.1/2].

    Signature
    (type-integer-promote type ienv) → new-type
    Arguments
    type — Guard (typep type).
    ienv — Guard (ienvp ienv).
    Returns
    new-type — Type (typep new-type).

    This only changes integer types of rank lower than int; the other types are left unchanged. We need the implementation environment because the new type may depend on the relative range of the initial type and signed int. The range of _Bool always fits within signed int, and so do signed char and signed short. For unsigned char and unsigned short, as well as for char (which may have the same range as unsigned char), we need to compare the maxima, and return either signed int or unsigned int as the promoted type.

    The rank of an enumerated type (which is an integer type) is implementation-defined, and could even vary based on the program, as mentioned in footnote 131 of [C17:6.7.2.2/4]. Thus, for now we promote the (one) enumerated type to unknown.

    Definitions and Theorems

    Function: type-integer-promote

    (defun type-integer-promote (type ienv)
      (declare (xargs :guard (and (typep type) (ienvp ienv))))
      (declare (xargs :guard (type-arithmeticp type)))
      (type-case type :bool (type-sint)
                 :char
                 (if (<= (ienv->char-max ienv)
                         (ienv->sint-max ienv))
                     (type-sint)
                   (type-uint))
                 :schar (type-sint)
                 :uchar
                 (if (<= (ienv->uchar-max ienv)
                         (ienv->sint-max ienv))
                     (type-sint)
                   (type-uint))
                 :sshort (type-sint)
                 :ushort
                 (if (<= (ienv->ushort-max ienv)
                         (ienv->sint-max ienv))
                     (type-sint)
                   (type-uint))
                 :enum (type-unknown)
                 :otherwise (type-fix type)))

    Theorem: typep-of-type-integer-promote

    (defthm typep-of-type-integer-promote
      (b* ((new-type (type-integer-promote type ienv)))
        (typep new-type))
      :rule-classes :rewrite)

    Theorem: type-integer-promotedp-of-type-integer-promote

    (defthm type-integer-promotedp-of-type-integer-promote
      (b* ((new-type (type-integer-promote type ienv)))
        (type-integer-promotedp new-type))
      :rule-classes :rewrite)

    Theorem: type-count-of-type-integer-promote

    (defthm type-count-of-type-integer-promote
      (equal (type-count (type-integer-promote type ienv))
             (type-count type)))

    Theorem: type-integer-promote-of-type-fix-type

    (defthm type-integer-promote-of-type-fix-type
      (equal (type-integer-promote (type-fix type)
                                   ienv)
             (type-integer-promote type ienv)))

    Theorem: type-integer-promote-type-equiv-congruence-on-type

    (defthm type-integer-promote-type-equiv-congruence-on-type
      (implies (type-equiv type type-equiv)
               (equal (type-integer-promote type ienv)
                      (type-integer-promote type-equiv ienv)))
      :rule-classes :congruence)

    Theorem: type-integer-promote-of-ienv-fix-ienv

    (defthm type-integer-promote-of-ienv-fix-ienv
      (equal (type-integer-promote type (ienv-fix ienv))
             (type-integer-promote type ienv)))

    Theorem: type-integer-promote-ienv-equiv-congruence-on-ienv

    (defthm type-integer-promote-ienv-equiv-congruence-on-ienv
      (implies (ienv-equiv ienv ienv-equiv)
               (equal (type-integer-promote type ienv)
                      (type-integer-promote type ienv-equiv)))
      :rule-classes :congruence)