Skip to content

Commit 541515d

Browse files
committed
M0-2-1 restore test
1 parent d47f5ec commit 541515d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
No expected results have yet been specified
1+
| test.cpp:37:3:37:18 | ... = ... | An object $@ assigned to overlapping object $@. | test.cpp:37:9:37:10 | m2 | m2 | test.cpp:37:17:37:18 | m1 | m1 |

cpp/autosar/test/rules/M0-2-1/ObjectAssignedToAnOverlappingObject.testref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
struct s1 {
3+
int m1[10];
4+
};
5+
struct s2 {
6+
int m1;
7+
struct s1 m2;
8+
};
9+
10+
union u {
11+
struct s1 m1;
12+
struct s2 m2;
13+
};
14+
15+
typedef struct {
16+
char buf[8];
17+
} Union_t;
18+
19+
typedef union {
20+
21+
unsigned char uc[24];
22+
23+
struct {
24+
Union_t prefix;
25+
Union_t suffix;
26+
} fnv;
27+
28+
struct {
29+
unsigned char padding[16];
30+
Union_t suffix;
31+
} diff;
32+
33+
} UnionSecret_t;
34+
35+
void overlapping_access() {
36+
u u1;
37+
u1.m2.m2 = u1.m1; // NON_COMPLIANT, different struct. u1.m2 and u1.m1
38+
}
39+
40+
void cross_copy() {
41+
UnionSecret_t hash1;
42+
hash1.diff.suffix =
43+
hash1.fnv.suffix; // COMPLIANT (copy across structs), but safe.
44+
}
45+
46+
void internal_shift() {
47+
UnionSecret_t hash1;
48+
hash1.fnv.prefix = hash1.fnv.suffix; // COMPLIANT, same struct.
49+
}
50+
51+
void separate_access() {
52+
UnionSecret_t hash1, hash2;
53+
hash2.diff.suffix = hash1.fnv.suffix; // COMPLIANT, different union.
54+
}

0 commit comments

Comments
 (0)