Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug with how non power 2 types were written to memory #246

Closed
wants to merge 1 commit into from

Conversation

kren1
Copy link
Contributor

@kren1 kren1 commented Jun 22, 2015

This is meant to fix a bug which manifests itself in the following two snippets:

union U0 {
    signed f3 :18;
};

static union U0 g_988 = { 0UL };

int main(int argc, char* argv[]) {
    g_988.f3 = 534;
    printf("f3 %d \n", g_988.f3);
    return 0;
}

This one works on the current master if pragma pack(1) is removed:

#include <stdio.h>
#pragma pack(1)
struct S0 {
    signed f0 :20;
};

static struct S0 x;
int main(int argc, char* argv[]) {

    x = (struct S0 ) { .f0 = 32 };
    printf("integer %d\n", x.f0);
    return x.f0;
}

What happens is that in these cases w = 24, which makes it jump to Int8 case in the switch(w), which causes the wrong value to be stored. I've added a check to make sure that w is a power of 2, so it definitively fits into one of the switch cases and uses the slow version in all the others.

I think this is a better option than adding Int24 into the switch since then all the others are also needed.

@ccadar
Copy link
Contributor

ccadar commented Jun 22, 2015

Thanks, @kren1. Just a comment to document that this happens only with LLVM 3.4, not 2.9.

@delcypher
Copy link
Contributor

@ccadar Is there any reason not to merge this?

@delcypher
Copy link
Contributor

I've manually merged this commit with a minor tweak.

@delcypher delcypher closed this Dec 17, 2015
gladtbx pushed a commit to gladtbx/klee that referenced this pull request Feb 7, 2017
….9 explicitely requir assertions to be enabled, in 3.4 we ask users to use LLVM packages, which are built in Release mode. This was prompted by issue klee#246, where the bug would have resulted in an easier-to-debug assert failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants