Skip to content

Commit dbea9ca

Browse files
committed
Add regression tests for compound literal pointers
Four regression tests were added under the “Compound Literals” section in `tests/driver.sh` 1. `char *s = (char[]){...}` scalar-sum case → returns 200 2. `short *s = (short[]){...}` scalar-sum case → returns 6 3. Ternary returning `int *` with the literal in the false branch when the condition is true → returns 60 4. The same ternary with the condition false, selecting the literal branch → returns 6
1 parent feddce5 commit dbea9ca

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

tests/driver.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,36 @@ int main() {
47434743
}
47444744
EOF
47454745

4746+
try_ 200 << EOF
4747+
int main(void) {
4748+
char *s = (char[]){'A', 'B', 'C', 'D', 'E'};
4749+
return s[0] + s[1] + s[4]; /* 65 + 66 + 69 */
4750+
}
4751+
EOF
4752+
4753+
try_ 6 << EOF
4754+
int main(void) {
4755+
short *s = (short[]){1, 2, 3, 4, 5};
4756+
return s[0] + s[4];
4757+
}
4758+
EOF
4759+
4760+
try_ 60 << EOF
4761+
int main(void) {
4762+
int arr[] = {10, 20, 30, 40, 50};
4763+
int *selected = 1 ? arr : (int[]){1, 2, 3, 4, 5};
4764+
return selected[0] + selected[4];
4765+
}
4766+
EOF
4767+
4768+
try_ 6 << EOF
4769+
int main(void) {
4770+
int arr[] = {10, 20, 30, 40, 50};
4771+
int *selected = 0 ? arr : (int[]){1, 2, 3, 4, 5};
4772+
return selected[0] + selected[4];
4773+
}
4774+
EOF
4775+
47464776
try_ 120 << EOF
47474777
int main() {
47484778
/* Complex expression with mixed compound literals */

tests/snapshots/fib-riscv.json

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

tests/snapshots/hello-riscv.json

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

0 commit comments

Comments
 (0)