Skip to content

Commit cc86cd4

Browse files
committed
Add regression tests for compound literal pointers
Four regression tests were added under the “Compound Literals” section in `tests/driver.sh` The tests cover: - char[] compound literal assigned to char* (sum = 200) - short[] compound literal assigned to short* (sum = 6) - ternary returning int* with literal in the false branch (true case) - ternary returning int* selecting the literal branch (false case)
1 parent bd68c7b commit cc86cd4

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

tests/driver.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4759,6 +4759,36 @@ int main() {
47594759
}
47604760
EOF
47614761

4762+
try_ 200 << EOF
4763+
int main(void) {
4764+
char *s = (char[]){'A', 'B', 'C', 'D', 'E'};
4765+
return s[0] + s[1] + s[4]; /* 65 + 66 + 69 */
4766+
}
4767+
EOF
4768+
4769+
try_ 6 << EOF
4770+
int main(void) {
4771+
short *s = (short[]){1, 2, 3, 4, 5};
4772+
return s[0] + s[4];
4773+
}
4774+
EOF
4775+
4776+
try_ 60 << EOF
4777+
int main(void) {
4778+
int arr[] = {10, 20, 30, 40, 50};
4779+
int *selected = 1 ? arr : (int[]){1, 2, 3, 4, 5};
4780+
return selected[0] + selected[4];
4781+
}
4782+
EOF
4783+
4784+
try_ 6 << EOF
4785+
int main(void) {
4786+
int arr[] = {10, 20, 30, 40, 50};
4787+
int *selected = 0 ? arr : (int[]){1, 2, 3, 4, 5};
4788+
return selected[0] + selected[4];
4789+
}
4790+
EOF
4791+
47624792
try_ 120 << EOF
47634793
int main() {
47644794
/* Complex expression with mixed compound literals */

tests/snapshots/fib-arm-static.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/fib-riscv-static.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/hello-arm-static.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/hello-riscv-static.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)