• 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
          • 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
          • 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
    • Static-semantics

    Check-iconst

    Check an integer constant.

    Signature
    (check-iconst ic) → type
    Arguments
    ic — Guard (iconstp ic).
    Returns
    type — Type (type-resultp type).

    This is according to [C17:6.4.4.1/5]: based on the suffixes and the base, we find the first type that suffices to represent the value, in the lists indicated in the table, and we return that type. If the value is too large, the integer constant is illegal.

    This is the static counterpart of eval-iconst.

    Definitions and Theorems

    Function: check-iconst

    (defun check-iconst (ic)
     (declare (xargs :guard (iconstp ic)))
     (let ((__function__ 'check-iconst))
      (declare (ignorable __function__))
      (b* ((ic (iconst-fix ic)) ((iconst ic) ic))
       (if ic.unsignedp
        (iconst-length-case
             ic.length
             :none (cond ((uint-integerp ic.value) (type-uint))
                         ((ulong-integerp ic.value) (type-ulong))
                         ((ullong-integerp ic.value)
                          (type-ullong))
                         (t (reserrf (list :iconst-out-of-range ic))))
             :long (cond ((ulong-integerp ic.value) (type-ulong))
                         ((ullong-integerp ic.value)
                          (type-ullong))
                         (t (reserrf (list :iconst-out-of-range ic))))
             :llong (cond ((ullong-integerp ic.value)
                           (type-ullong))
                          (t (reserrf (list :iconst-out-of-range ic)))))
        (iconst-length-case
             ic.length :none
             (if (iconst-base-case ic.base :dec)
                 (cond ((sint-integerp ic.value) (type-sint))
                       ((slong-integerp ic.value) (type-slong))
                       ((sllong-integerp ic.value)
                        (type-sllong))
                       (t (reserrf (list :iconst-out-of-range ic))))
               (cond ((sint-integerp ic.value) (type-sint))
                     ((uint-integerp ic.value) (type-uint))
                     ((slong-integerp ic.value) (type-slong))
                     ((ulong-integerp ic.value) (type-ulong))
                     ((sllong-integerp ic.value)
                      (type-sllong))
                     ((ullong-integerp ic.value)
                      (type-ullong))
                     (t (reserrf (list :iconst-out-of-range ic)))))
             :long
             (if (iconst-base-case ic.base :dec)
                 (cond ((slong-integerp ic.value) (type-slong))
                       ((sllong-integerp ic.value)
                        (type-sllong))
                       (t (reserrf (list :iconst-out-of-range ic))))
               (cond ((slong-integerp ic.value) (type-slong))
                     ((ulong-integerp ic.value) (type-ulong))
                     ((sllong-integerp ic.value)
                      (type-sllong))
                     ((ullong-integerp ic.value)
                      (type-ullong))
                     (t (reserrf (list :iconst-out-of-range ic)))))
             :llong
             (if (iconst-base-case ic.base :dec)
                 (cond ((sllong-integerp ic.value)
                        (type-sllong))
                       (t (reserrf (list :iconst-out-of-range ic))))
               (cond ((sllong-integerp ic.value)
                      (type-sllong))
                     ((ullong-integerp ic.value)
                      (type-ullong))
                     (t (reserrf (list :iconst-out-of-range ic))))))))))

    Theorem: type-resultp-of-check-iconst

    (defthm type-resultp-of-check-iconst
      (b* ((type (check-iconst ic)))
        (type-resultp type))
      :rule-classes :rewrite)

    Theorem: check-iconst-of-iconst-fix-ic

    (defthm check-iconst-of-iconst-fix-ic
      (equal (check-iconst (iconst-fix ic))
             (check-iconst ic)))

    Theorem: check-iconst-iconst-equiv-congruence-on-ic

    (defthm check-iconst-iconst-equiv-congruence-on-ic
      (implies (iconst-equiv ic ic-equiv)
               (equal (check-iconst ic)
                      (check-iconst ic-equiv)))
      :rule-classes :congruence)