Commit 9823bd9
committed
[cc] fixes
(not included: comment and other minor fix descriptions)
Fixed a bug in the C compiler's declarator parser (cc/parse/parser.rs) where outer pointer modifiers in grouped declarators were applied in the wrong order.
The Bug
For declarations like struct node *(*fp)(int) (function pointer returning a pointer) and int *(*p)[3] (pointer to array of pointers), the type chain was being built incorrectly:
Before (wrong):
- struct node *(*fp)(int) → Pointer → Pointer → Function → struct node
- int *(*p)[3] → Pointer → Pointer → Array → int
After (correct):
- struct node *(*fp)(int) → Pointer → Function(returns Pointer → struct node)
- int *(*p)[3] → Pointer → Array(of Pointer → int)
The Fix
In parse_declarator(), moved the application of outer pointer modifiers before applying function parameters and array dimensions (lines 4040-4055). This ensures the outer * becomes part of the function's return type or array element type, not an extra wrapper around the whole construct.
Files Modified
1. cc/parse/parser.rs - Fixed type chain building order in grouped declarators
2. Added two regression tests:
- test_function_pointer_returning_struct_pointer
- test_pointer_to_array_of_pointers1 parent ff3b1ff commit 9823bd9
File tree
7 files changed
+706
-28
lines changed- cc
- arch/x86_64
- ir
- parse
- scripts
- tests/features
7 files changed
+706
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1287 | 1287 | | |
1288 | 1288 | | |
1289 | 1289 | | |
1290 | | - | |
| 1290 | + | |
1291 | 1291 | | |
1292 | 1292 | | |
1293 | 1293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4011 | 4011 | | |
4012 | 4012 | | |
4013 | 4013 | | |
4014 | | - | |
4015 | | - | |
4016 | | - | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
4017 | 4035 | | |
4018 | | - | |
4019 | | - | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
4020 | 4039 | | |
4021 | 4040 | | |
4022 | 4041 | | |
4023 | 4042 | | |
4024 | 4043 | | |
4025 | | - | |
4026 | | - | |
| 4044 | + | |
| 4045 | + | |
4027 | 4046 | | |
4028 | 4047 | | |
4029 | 4048 | | |
| |||
4038 | 4057 | | |
4039 | 4058 | | |
4040 | 4059 | | |
4041 | | - | |
4042 | | - | |
4043 | | - | |
4044 | | - | |
4045 | | - | |
4046 | | - | |
4047 | | - | |
4048 | | - | |
4049 | | - | |
4050 | | - | |
4051 | | - | |
4052 | | - | |
4053 | | - | |
4054 | | - | |
4055 | | - | |
4056 | 4060 | | |
4057 | 4061 | | |
4058 | 4062 | | |
4059 | | - | |
4060 | | - | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
4061 | 4066 | | |
4062 | 4067 | | |
4063 | 4068 | | |
| |||
7753 | 7758 | | |
7754 | 7759 | | |
7755 | 7760 | | |
| 7761 | + | |
| 7762 | + | |
| 7763 | + | |
| 7764 | + | |
| 7765 | + | |
| 7766 | + | |
| 7767 | + | |
| 7768 | + | |
| 7769 | + | |
| 7770 | + | |
| 7771 | + | |
| 7772 | + | |
| 7773 | + | |
| 7774 | + | |
| 7775 | + | |
| 7776 | + | |
| 7777 | + | |
| 7778 | + | |
| 7779 | + | |
| 7780 | + | |
| 7781 | + | |
| 7782 | + | |
| 7783 | + | |
| 7784 | + | |
| 7785 | + | |
| 7786 | + | |
| 7787 | + | |
| 7788 | + | |
| 7789 | + | |
| 7790 | + | |
| 7791 | + | |
| 7792 | + | |
| 7793 | + | |
| 7794 | + | |
| 7795 | + | |
| 7796 | + | |
| 7797 | + | |
| 7798 | + | |
| 7799 | + | |
| 7800 | + | |
| 7801 | + | |
| 7802 | + | |
| 7803 | + | |
| 7804 | + | |
| 7805 | + | |
| 7806 | + | |
| 7807 | + | |
| 7808 | + | |
| 7809 | + | |
| 7810 | + | |
| 7811 | + | |
| 7812 | + | |
| 7813 | + | |
| 7814 | + | |
| 7815 | + | |
| 7816 | + | |
| 7817 | + | |
| 7818 | + | |
| 7819 | + | |
| 7820 | + | |
| 7821 | + | |
| 7822 | + | |
| 7823 | + | |
| 7824 | + | |
| 7825 | + | |
| 7826 | + | |
| 7827 | + | |
| 7828 | + | |
| 7829 | + | |
| 7830 | + | |
| 7831 | + | |
| 7832 | + | |
| 7833 | + | |
| 7834 | + | |
| 7835 | + | |
| 7836 | + | |
| 7837 | + | |
| 7838 | + | |
| 7839 | + | |
| 7840 | + | |
| 7841 | + | |
| 7842 | + | |
| 7843 | + | |
| 7844 | + | |
| 7845 | + | |
| 7846 | + | |
| 7847 | + | |
| 7848 | + | |
| 7849 | + | |
| 7850 | + | |
7756 | 7851 | | |
7757 | 7852 | | |
7758 | 7853 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
0 commit comments