Skip to content

Commit 37fcac6

Browse files
authored
Fix encoded floats appearing in relational exps. (#584)
* Fix encoded floats appearing in relational exps. * Test. * Fix test.
1 parent 5a3b266 commit 37fcac6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

semantics/c/language/common/expr/relational.k

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ module C-COMMON-EXPR-RELATIONAL
341341
requires notBool hasLint
342342
[structural]
343343

344+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) == tv(encodedValue(V':EncodableValue, N, M), T'::UType)
345+
=> tv(V, T) == tv(V', T')
346+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) != tv(encodedValue(V':EncodableValue, N, M), T'::UType)
347+
=> tv(V, T) != tv(V', T')
348+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) < tv(encodedValue(V':EncodableValue, N, M), T'::UType)
349+
=> tv(V, T) < tv(V', T')
350+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) <= tv(encodedValue(V':EncodableValue, N, M), T'::UType)
351+
=> tv(V, T) <= tv(V', T')
352+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) > tv(encodedValue(V':EncodableValue, N, M), T'::UType)
353+
=> tv(V, T) > tv(V', T')
354+
rule tv(encodedValue(V:EncodableValue, N:Int, M:Int), T::UType) >= tv(encodedValue(V':EncodableValue, N, M), T'::UType)
355+
=> tv(V, T) >= tv(V', T')
356+
344357
rule tv(encodedPtr(Loc:SymLoc, N:Int, M:Int), T::UType) == tv(encodedPtr(Loc':SymLoc, N:Int, M:Int), T'::UType)
345358
=> tv(Loc, T) == tv(Loc', T')
346359
rule tv(encodedPtr(Loc:SymLoc, N:Int, M:Int), T::UType) != tv(encodedPtr(Loc':SymLoc, N:Int, M:Int), T'::UType)

tests/unit-pass/memcmp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <string.h>
2+
3+
int main() {
4+
int x = 1;
5+
float y = 1;
6+
double z = 1;
7+
int * p = &x;
8+
return memcmp(&x, &x, sizeof(x))
9+
|| memcmp(&y, &y, sizeof(y))
10+
|| memcmp(&z, &z, sizeof(z))
11+
|| memcmp(&p, &p, sizeof(p));
12+
}

0 commit comments

Comments
 (0)