Skip to Content.
Sympa Menu

c-semantics - [C-Semantics] catching (some) bad union code

c-semantics AT lists.cs.illinois.edu

Subject: C Semantics in K Framework

List archive

[C-Semantics] catching (some) bad union code


Chronological Thread 
  • From: Chucky Ellison <celliso2 AT illinois.edu>
  • To: c-semantics AT cs.illinois.edu
  • Subject: [C-Semantics] catching (some) bad union code
  • Date: Mon, 25 Jul 2011 00:47:11 -0500
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/c-semantics>
  • List-id: C Semantics in K Framework <c-semantics.cs.illinois.edu>

Everybody,

The latest version of kcc (r941) should be catching some new kinds of union errors I was missing before.  As usual, you'll need to update K too.

One such program it catches now, which it wasn't catching before, is the following:
union U {
    char a;
    int b;
} u;
int main(void){
    u.b = 0;
    u.a = 0;
    return u.b;    // error here, caught now
}

After writing to u.a, some of the bytes of u.b have become unspecified.  Basically, any program where you say union.field=foo will invalidate the bytes of the union not belonging to the field.  However, this version won't catch structs or unions nested in unions (example below).  I'm still trying to figure out a generic solution to this, but I thought this improvement might be useful in the meanwhile.

An example of an unspecified program program kcc still fails to detect is the following:
union T {
    char a;
};
union U {
    union T t;
    int b;
} u;
int main(void){
    u.b = 0;
    u.t.a = 0;
    return u.b;    // error here, still not caught
}


This version includes a reworking of the way types are represented in kcc to allow more flexibility.  This was a huge change, so if you see anything funky, let me know.

-Chucky



Archive powered by MHonArc 2.6.16.

Top of Page