| @@ -551,4 +551,114 @@ int main(int argc, char **argv) · 550 unmodified lines |
| 551 | 551 | |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | +#elif defined test_const_array_member_addr_ok |
| 555 | + |
| 556 | +typedef int int_array[1]; |
| 557 | +typedef struct { int_array arr; } my_struct; |
| 558 | + |
| 559 | +int_array const *get_array(const my_struct *s) |
| 560 | +{ |
| 561 | + return &(s->arr); |
| 562 | +} |
| 563 | + |
| 564 | +#elif defined test_const_array_member_decay_ok |
| 565 | + |
| 566 | +typedef int int_array[1]; |
| 567 | +typedef struct { int_array arr; } my_struct; |
| 568 | + |
| 569 | +const int *good_decay(const my_struct *s) |
| 570 | +{ |
| 571 | + return s->arr; |
| 572 | +} |
| 573 | + |
| 574 | +#elif defined test_const_array_member_addr_bad |
| 575 | + |
| 576 | +typedef int int_array[1]; |
| 577 | +typedef struct { int_array arr; } my_struct; |
| 578 | + |
| 579 | +int_array *bad_array_addr(const my_struct *s) |
| 580 | +{ |
| 581 | + return &(s->arr); |
| 582 | +} |
| 583 | + |
| 584 | +#elif defined test_const_array_member_decay_bad |
| 585 | + |
| 586 | +typedef int int_array[1]; |
| 587 | +typedef struct { int_array arr; } my_struct; |
| 588 | + |
| 589 | +int *bad_decay(const my_struct *s) |
| 590 | +{ |
| 591 | + return s->arr; |
| 592 | +} |
| 593 | + |
| 594 | +#elif defined test_const_array_member_write_bad |
| 595 | + |
| 596 | +typedef int int_array[1]; |
| 597 | +typedef struct { int_array arr; } my_struct; |
| 598 | + |
| 599 | +void bad_write(const my_struct *s) |
| 600 | +{ |
| 601 | + s->arr[0] = 1; |
| 602 | +} |
| 603 | + |
| 604 | +#elif defined test_const_struct_array_member_write_bad |
| 605 | + |
| 606 | +typedef struct { int x; } inner; |
| 607 | +typedef struct { inner arr[1]; } outer; |
| 608 | + |
| 609 | +void bad_inner_write(const outer *s) |
| 610 | +{ |
| 611 | + s->arr[0].x = 1; |
| 612 | +} |
| 613 | + |
| 614 | +#elif defined test_volatile_array_member_addr_ok |
| 615 | + |
| 616 | +typedef int int_array[1]; |
| 617 | +typedef struct { int_array arr; } my_struct; |
| 618 | + |
| 619 | +int_array volatile *get_volatile_array(volatile my_struct *s) |
| 620 | +{ |
| 621 | + return &(s->arr); |
| 622 | +} |
| 623 | + |
| 624 | +#elif defined test_volatile_array_member_decay_ok |
| 625 | + |
| 626 | +typedef int int_array[1]; |
| 627 | +typedef struct { int_array arr; } my_struct; |
| 628 | + |
| 629 | +volatile int *good_volatile_decay(volatile my_struct *s) |
| 630 | +{ |
| 631 | + return s->arr; |
| 632 | +} |
| 633 | + |
| 634 | +#elif defined test_volatile_array_member_addr_bad |
| 635 | + |
| 636 | +typedef int int_array[1]; |
| 637 | +typedef struct { int_array arr; } my_struct; |
| 638 | + |
| 639 | +int_array *bad_volatile_array_addr(volatile my_struct *s) |
| 640 | +{ |
| 641 | + return &(s->arr); |
| 642 | +} |
| 643 | + |
| 644 | +#elif defined test_volatile_array_member_decay_bad |
| 645 | + |
| 646 | +typedef int int_array[1]; |
| 647 | +typedef struct { int_array arr; } my_struct; |
| 648 | + |
| 649 | +int *bad_volatile_decay(volatile my_struct *s) |
| 650 | +{ |
| 651 | + return s->arr; |
| 652 | +} |
| 653 | + |
| 654 | +#elif defined test_volatile_array_member_write_ok |
| 655 | + |
| 656 | +typedef int int_array[1]; |
| 657 | +typedef struct { int_array arr; } my_struct; |
| 658 | + |
| 659 | +void good_volatile_write(volatile my_struct *s) |
| 660 | +{ |
| 661 | + s->arr[0] = 1; |
| 662 | +} |
| 663 | + |
| 554 | 664 | #endif |