Mill Computing, Inc. Forums The Mill Architecture array bound checking

  • Author
    Posts
  • goldbug
    Participant
    Post count: 29
    #3063 |

    Is there anything mill specific to do array bounds check?

    for example:

    
    void foo()
    {
       int myarray1[3];
       int myarray2[3];
       int myarray3[3];
    
       // undefined behavior,  will probably override something in either array 1 or array 3
       // depending on how things are organized in the stack
       myarray2[3] = 5;
    }

    In other platforms we have valgrind, which adds array bounds checking instructions at great performance cost.
    Ideally the application would abort rather than continue silently, and doing the check would take no extra cycles.

    I suppose in this example the compiler could add range checking operations (lss, geq, pick and brtr), which would be “free” since they could be squeezed in the regular program instructions. But if the array size is not known as compile time such as when you receive a pointer to the array, it would be a lot more complicated.

  • Ivan Godard
    Keymaster
    Post count: 460

    Yes and no.
    We have to support C, and C has no arrays in expressions – any array name is promoted to a pointer. For explicit indexing where the type is known the compiler can insert explicit bounds checks, but often the underlying type is no longer known. For other languages, or under compiler option, checking using ordinary operations and the machine width does about as well as custom operations for bounds checking. The predicated fault op (for stores) and the one-legged NaR pick (for loads and LEA) are useful.

    Valgrind and similar tools check for access outside of an allocated object, not just array indexing. To do that properly requires capabilities or fat pointers, which break data structures that assume skinny pointers. We have some NYF support for this usage.

You must be logged in to reply to this topic.