| ... | ... | @@ -1830,33 +1830,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1830 | 1830 | \\} |
| 1831 | 1831 | }); |
| 1832 | 1832 | |
| 1833 | | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// |
| 1834 | | |
| 1835 | | cases.add("macro defines string literal with hex", |
| 1836 | | \\#define FOO "aoeu\xab derp" |
| 1837 | | \\#define FOO2 "aoeu\x0007a derp" |
| 1838 | | \\#define FOO_CHAR '\xfF' |
| 1839 | | , &[_][]const u8{ |
| 1840 | | \\pub const FOO = "aoeu\xab derp"; |
| 1841 | | , |
| 1842 | | \\pub const FOO2 = "aoeuz derp"; |
| 1843 | | , |
| 1844 | | \\pub const FOO_CHAR = 255; |
| 1845 | | }); |
| 1846 | | |
| 1847 | | cases.add("macro defines string literal with octal", |
| 1848 | | \\#define FOO "aoeu\023 derp" |
| 1849 | | \\#define FOO2 "aoeu\0234 derp" |
| 1850 | | \\#define FOO_CHAR '\077' |
| 1851 | | , &[_][]const u8{ |
| 1852 | | \\pub const FOO = "aoeu\x13 derp"; |
| 1853 | | , |
| 1854 | | \\pub const FOO2 = "aoeu\x134 derp"; |
| 1855 | | , |
| 1856 | | \\pub const FOO_CHAR = 63; |
| 1857 | | }); |
| 1858 | | |
| 1859 | | cases.addC("shift right assign", |
| 1833 | cases.add_2("shift right assign", |
| 1860 | 1834 | \\int log2(unsigned a) { |
| 1861 | 1835 | \\ int i = 0; |
| 1862 | 1836 | \\ while (a > 0) { |
| ... | ... | @@ -1864,18 +1838,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1864 | 1838 | \\ } |
| 1865 | 1839 | \\ return i; |
| 1866 | 1840 | \\} |
| 1867 | | , &[_][]const u8{ |
| 1868 | | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 1869 | | \\ var a = _arg_a; |
| 1841 | , &[_][]const u8{// TODO function arguments should be copied |
| 1842 | \\pub export fn log2(a: c_uint) c_int { |
| 1870 | 1843 | \\ var i: c_int = 0; |
| 1871 | | \\ while (a > @as(c_uint, 0)) { |
| 1872 | | \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1); |
| 1844 | \\ while ((a > @as(c_uint, 0))) { |
| 1845 | \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); |
| 1873 | 1846 | \\ } |
| 1874 | 1847 | \\ return i; |
| 1875 | 1848 | \\} |
| 1876 | 1849 | }); |
| 1877 | 1850 | |
| 1878 | | cases.addC("shift right assign with a fixed size type", |
| 1851 | cases.add_2("shift right assign with a fixed size type", |
| 1879 | 1852 | \\#include <stdint.h> |
| 1880 | 1853 | \\int log2(uint32_t a) { |
| 1881 | 1854 | \\ int i = 0; |
| ... | ... | @@ -1885,27 +1858,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1885 | 1858 | \\ return i; |
| 1886 | 1859 | \\} |
| 1887 | 1860 | , &[_][]const u8{ |
| 1888 | | \\pub export fn log2(_arg_a: u32) c_int { |
| 1889 | | \\ var a = _arg_a; |
| 1861 | \\pub export fn log2(a: u32) c_int { |
| 1890 | 1862 | \\ var i: c_int = 0; |
| 1891 | | \\ while (a > @as(c_uint, 0)) { |
| 1892 | | \\ a >>= @as(u5, 1); |
| 1863 | \\ while ((a > @as(c_uint, 0))) { |
| 1864 | \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); |
| 1893 | 1865 | \\ } |
| 1894 | 1866 | \\ return i; |
| 1895 | 1867 | \\} |
| 1896 | 1868 | }); |
| 1897 | 1869 | |
| 1898 | | cases.addC("__extension__ cast", |
| 1899 | | \\int foo(void) { |
| 1900 | | \\ return __extension__ 1; |
| 1901 | | \\} |
| 1902 | | , &[_][]const u8{ |
| 1903 | | \\pub export fn foo() c_int { |
| 1904 | | \\ return 1; |
| 1905 | | \\} |
| 1906 | | }); |
| 1907 | | |
| 1908 | | cases.addC("compound assignment operators", |
| 1870 | cases.add_2("compound assignment operators", |
| 1909 | 1871 | \\void foo(void) { |
| 1910 | 1872 | \\ int a = 0; |
| 1911 | 1873 | \\ a += (a += 1); |
| ... | ... | @@ -1920,50 +1882,50 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1920 | 1882 | , &[_][]const u8{ |
| 1921 | 1883 | \\pub export fn foo() void { |
| 1922 | 1884 | \\ var a: c_int = 0; |
| 1923 | | \\ a += (x: { |
| 1924 | | \\ const _ref = &a; |
| 1925 | | \\ _ref.* = (_ref.* + 1); |
| 1926 | | \\ break :x _ref.*; |
| 1885 | \\ a += (blk: { |
| 1886 | \\ const _ref_1 = &a; |
| 1887 | \\ _ref_1.* = _ref_1.* + 1; |
| 1888 | \\ break :blk _ref_1.*; |
| 1927 | 1889 | \\ }); |
| 1928 | | \\ a -= (x: { |
| 1929 | | \\ const _ref = &a; |
| 1930 | | \\ _ref.* = (_ref.* - 1); |
| 1931 | | \\ break :x _ref.*; |
| 1890 | \\ a -= (blk: { |
| 1891 | \\ const _ref_2 = &a; |
| 1892 | \\ _ref_2.* = _ref_2.* - 1; |
| 1893 | \\ break :blk _ref_2.*; |
| 1932 | 1894 | \\ }); |
| 1933 | | \\ a *= (x: { |
| 1934 | | \\ const _ref = &a; |
| 1935 | | \\ _ref.* = (_ref.* * 1); |
| 1936 | | \\ break :x _ref.*; |
| 1895 | \\ a *= (blk: { |
| 1896 | \\ const _ref_3 = &a; |
| 1897 | \\ _ref_3.* = _ref_3.* * 1; |
| 1898 | \\ break :blk _ref_3.*; |
| 1937 | 1899 | \\ }); |
| 1938 | | \\ a &= (x: { |
| 1939 | | \\ const _ref = &a; |
| 1940 | | \\ _ref.* = (_ref.* & 1); |
| 1941 | | \\ break :x _ref.*; |
| 1900 | \\ a &= (blk: { |
| 1901 | \\ const _ref_4 = &a; |
| 1902 | \\ _ref_4.* = _ref_4.* & 1; |
| 1903 | \\ break :blk _ref_4.*; |
| 1942 | 1904 | \\ }); |
| 1943 | | \\ a |= (x: { |
| 1944 | | \\ const _ref = &a; |
| 1945 | | \\ _ref.* = (_ref.* | 1); |
| 1946 | | \\ break :x _ref.*; |
| 1905 | \\ a |= (blk: { |
| 1906 | \\ const _ref_5 = &a; |
| 1907 | \\ _ref_5.* = _ref_5.* | 1; |
| 1908 | \\ break :blk _ref_5.*; |
| 1947 | 1909 | \\ }); |
| 1948 | | \\ a ^= (x: { |
| 1949 | | \\ const _ref = &a; |
| 1950 | | \\ _ref.* = (_ref.* ^ 1); |
| 1951 | | \\ break :x _ref.*; |
| 1910 | \\ a ^= (blk: { |
| 1911 | \\ const _ref_6 = &a; |
| 1912 | \\ _ref_6.* = _ref_6.* ^ 1; |
| 1913 | \\ break :blk _ref_6.*; |
| 1952 | 1914 | \\ }); |
| 1953 | | \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: { |
| 1954 | | \\ const _ref = &a; |
| 1955 | | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1)); |
| 1956 | | \\ break :x _ref.*; |
| 1915 | \\ a >>= @as(@import("std").math.Log2Int(c_int), (blk: { |
| 1916 | \\ const _ref_7 = &a; |
| 1917 | \\ _ref_7.* = _ref_7.* >> @as(@import("std").math.Log2Int(c_int), 1); |
| 1918 | \\ break :blk _ref_7.*; |
| 1957 | 1919 | \\ })); |
| 1958 | | \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: { |
| 1959 | | \\ const _ref = &a; |
| 1960 | | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1)); |
| 1961 | | \\ break :x _ref.*; |
| 1920 | \\ a <<= @as(@import("std").math.Log2Int(c_int), (blk: { |
| 1921 | \\ const _ref_8 = &a; |
| 1922 | \\ _ref_8.* = _ref_8.* << @as(@import("std").math.Log2Int(c_int), 1); |
| 1923 | \\ break :blk _ref_8.*; |
| 1962 | 1924 | \\ })); |
| 1963 | 1925 | \\} |
| 1964 | 1926 | }); |
| 1965 | 1927 | |
| 1966 | | cases.addC("compound assignment operators unsigned", |
| 1928 | cases.add_2("compound assignment operators unsigned", |
| 1967 | 1929 | \\void foo(void) { |
| 1968 | 1930 | \\ unsigned a = 0; |
| 1969 | 1931 | \\ a += (a += 1); |
| ... | ... | @@ -1978,50 +1940,50 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1978 | 1940 | , &[_][]const u8{ |
| 1979 | 1941 | \\pub export fn foo() void { |
| 1980 | 1942 | \\ var a: c_uint = @as(c_uint, 0); |
| 1981 | | \\ a +%= (x: { |
| 1982 | | \\ const _ref = &a; |
| 1983 | | \\ _ref.* = (_ref.* +% @as(c_uint, 1)); |
| 1984 | | \\ break :x _ref.*; |
| 1943 | \\ a +%= (blk: { |
| 1944 | \\ const _ref_1 = &a; |
| 1945 | \\ _ref_1.* = _ref_1.* +% @as(c_uint, 1); |
| 1946 | \\ break :blk _ref_1.*; |
| 1985 | 1947 | \\ }); |
| 1986 | | \\ a -%= (x: { |
| 1987 | | \\ const _ref = &a; |
| 1988 | | \\ _ref.* = (_ref.* -% @as(c_uint, 1)); |
| 1989 | | \\ break :x _ref.*; |
| 1948 | \\ a -%= (blk: { |
| 1949 | \\ const _ref_2 = &a; |
| 1950 | \\ _ref_2.* = _ref_2.* -% @as(c_uint, 1); |
| 1951 | \\ break :blk _ref_2.*; |
| 1990 | 1952 | \\ }); |
| 1991 | | \\ a *%= (x: { |
| 1992 | | \\ const _ref = &a; |
| 1993 | | \\ _ref.* = (_ref.* *% @as(c_uint, 1)); |
| 1994 | | \\ break :x _ref.*; |
| 1953 | \\ a *%= (blk: { |
| 1954 | \\ const _ref_3 = &a; |
| 1955 | \\ _ref_3.* = _ref_3.* *% @as(c_uint, 1); |
| 1956 | \\ break :blk _ref_3.*; |
| 1995 | 1957 | \\ }); |
| 1996 | | \\ a &= (x: { |
| 1997 | | \\ const _ref = &a; |
| 1998 | | \\ _ref.* = (_ref.* & @as(c_uint, 1)); |
| 1999 | | \\ break :x _ref.*; |
| 1958 | \\ a &= (blk: { |
| 1959 | \\ const _ref_4 = &a; |
| 1960 | \\ _ref_4.* = _ref_4.* & @as(c_uint, 1); |
| 1961 | \\ break :blk _ref_4.*; |
| 2000 | 1962 | \\ }); |
| 2001 | | \\ a |= (x: { |
| 2002 | | \\ const _ref = &a; |
| 2003 | | \\ _ref.* = (_ref.* | @as(c_uint, 1)); |
| 2004 | | \\ break :x _ref.*; |
| 1963 | \\ a |= (blk: { |
| 1964 | \\ const _ref_5 = &a; |
| 1965 | \\ _ref_5.* = _ref_5.* | @as(c_uint, 1); |
| 1966 | \\ break :blk _ref_5.*; |
| 2005 | 1967 | \\ }); |
| 2006 | | \\ a ^= (x: { |
| 2007 | | \\ const _ref = &a; |
| 2008 | | \\ _ref.* = (_ref.* ^ @as(c_uint, 1)); |
| 2009 | | \\ break :x _ref.*; |
| 1968 | \\ a ^= (blk: { |
| 1969 | \\ const _ref_6 = &a; |
| 1970 | \\ _ref_6.* = _ref_6.* ^ @as(c_uint, 1); |
| 1971 | \\ break :blk _ref_6.*; |
| 2010 | 1972 | \\ }); |
| 2011 | | \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 2012 | | \\ const _ref = &a; |
| 2013 | | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1)); |
| 2014 | | \\ break :x _ref.*; |
| 1973 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: { |
| 1974 | \\ const _ref_7 = &a; |
| 1975 | \\ _ref_7.* = _ref_7.* >> @as(@import("std").math.Log2Int(c_int), 1); |
| 1976 | \\ break :blk _ref_7.*; |
| 2015 | 1977 | \\ })); |
| 2016 | | \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 2017 | | \\ const _ref = &a; |
| 2018 | | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1)); |
| 2019 | | \\ break :x _ref.*; |
| 1978 | \\ a <<= @as(@import("std").math.Log2Int(c_uint), (blk: { |
| 1979 | \\ const _ref_8 = &a; |
| 1980 | \\ _ref_8.* = _ref_8.* << @as(@import("std").math.Log2Int(c_int), 1); |
| 1981 | \\ break :blk _ref_8.*; |
| 2020 | 1982 | \\ })); |
| 2021 | 1983 | \\} |
| 2022 | 1984 | }); |
| 2023 | 1985 | |
| 2024 | | cases.addC("post increment/decrement", |
| 1986 | cases.add_2("post increment/decrement", |
| 2025 | 1987 | \\void foo(void) { |
| 2026 | 1988 | \\ int i = 0; |
| 2027 | 1989 | \\ unsigned u = 0; |
| ... | ... | @@ -2042,30 +2004,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2042 | 2004 | \\ i -= 1; |
| 2043 | 2005 | \\ u +%= 1; |
| 2044 | 2006 | \\ u -%= 1; |
| 2045 | | \\ i = (x: { |
| 2046 | | \\ const _ref = &i; |
| 2047 | | \\ const _tmp = _ref.*; |
| 2048 | | \\ _ref.* += 1; |
| 2049 | | \\ break :x _tmp; |
| 2050 | | \\ }); |
| 2051 | | \\ i = (x: { |
| 2052 | | \\ const _ref = &i; |
| 2053 | | \\ const _tmp = _ref.*; |
| 2054 | | \\ _ref.* -= 1; |
| 2055 | | \\ break :x _tmp; |
| 2056 | | \\ }); |
| 2057 | | \\ u = (x: { |
| 2058 | | \\ const _ref = &u; |
| 2059 | | \\ const _tmp = _ref.*; |
| 2060 | | \\ _ref.* +%= 1; |
| 2061 | | \\ break :x _tmp; |
| 2062 | | \\ }); |
| 2063 | | \\ u = (x: { |
| 2064 | | \\ const _ref = &u; |
| 2065 | | \\ const _tmp = _ref.*; |
| 2066 | | \\ _ref.* -%= 1; |
| 2067 | | \\ break :x _tmp; |
| 2068 | | \\ }); |
| 2007 | \\ i = blk: { |
| 2008 | \\ const _ref_1 = &i; |
| 2009 | \\ const _tmp_2 = _ref_1.*; |
| 2010 | \\ _ref_1.* += 1; |
| 2011 | \\ break :blk _tmp_2; |
| 2012 | \\ }; |
| 2013 | \\ i = blk: { |
| 2014 | \\ const _ref_3 = &i; |
| 2015 | \\ const _tmp_4 = _ref_3.*; |
| 2016 | \\ _ref_3.* -= 1; |
| 2017 | \\ break :blk _tmp_4; |
| 2018 | \\ }; |
| 2019 | \\ u = blk: { |
| 2020 | \\ const _ref_5 = &u; |
| 2021 | \\ const _tmp_6 = _ref_5.*; |
| 2022 | \\ _ref_5.* +%= 1; |
| 2023 | \\ break :blk _tmp_6; |
| 2024 | \\ }; |
| 2025 | \\ u = blk: { |
| 2026 | \\ const _ref_7 = &u; |
| 2027 | \\ const _tmp_8 = _ref_7.*; |
| 2028 | \\ _ref_7.* -%= 1; |
| 2029 | \\ break :blk _tmp_8; |
| 2030 | \\ }; |
| 2031 | \\} |
| 2032 | }); |
| 2033 | |
| 2034 | /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// |
| 2035 | |
| 2036 | cases.add("macro defines string literal with hex", |
| 2037 | \\#define FOO "aoeu\xab derp" |
| 2038 | \\#define FOO2 "aoeu\x0007a derp" |
| 2039 | \\#define FOO_CHAR '\xfF' |
| 2040 | , &[_][]const u8{ |
| 2041 | \\pub const FOO = "aoeu\xab derp"; |
| 2042 | , |
| 2043 | \\pub const FOO2 = "aoeuz derp"; |
| 2044 | , |
| 2045 | \\pub const FOO_CHAR = 255; |
| 2046 | }); |
| 2047 | |
| 2048 | cases.add("macro defines string literal with octal", |
| 2049 | \\#define FOO "aoeu\023 derp" |
| 2050 | \\#define FOO2 "aoeu\0234 derp" |
| 2051 | \\#define FOO_CHAR '\077' |
| 2052 | , &[_][]const u8{ |
| 2053 | \\pub const FOO = "aoeu\x13 derp"; |
| 2054 | , |
| 2055 | \\pub const FOO2 = "aoeu\x134 derp"; |
| 2056 | , |
| 2057 | \\pub const FOO_CHAR = 63; |
| 2058 | }); |
| 2059 | |
| 2060 | cases.addC("__extension__ cast", |
| 2061 | \\int foo(void) { |
| 2062 | \\ return __extension__ 1; |
| 2063 | \\} |
| 2064 | , &[_][]const u8{ |
| 2065 | \\pub export fn foo() c_int { |
| 2066 | \\ return 1; |
| 2069 | 2067 | \\} |
| 2070 | 2068 | }); |
| 2071 | 2069 | |
| ... | ... | @@ -2789,4 +2787,207 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2789 | 2787 | \\ }); |
| 2790 | 2788 | \\} |
| 2791 | 2789 | }); |
| 2790 | |
| 2791 | cases.addC("shift right assign", |
| 2792 | \\int log2(unsigned a) { |
| 2793 | \\ int i = 0; |
| 2794 | \\ while (a > 0) { |
| 2795 | \\ a >>= 1; |
| 2796 | \\ } |
| 2797 | \\ return i; |
| 2798 | \\} |
| 2799 | , &[_][]const u8{ |
| 2800 | \\pub export fn log2(_arg_a: c_uint) c_int { |
| 2801 | \\ var a = _arg_a; |
| 2802 | \\ var i: c_int = 0; |
| 2803 | \\ while (a > @as(c_uint, 0)) { |
| 2804 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1); |
| 2805 | \\ } |
| 2806 | \\ return i; |
| 2807 | \\} |
| 2808 | }); |
| 2809 | |
| 2810 | cases.addC("shift right assign with a fixed size type", |
| 2811 | \\#include <stdint.h> |
| 2812 | \\int log2(uint32_t a) { |
| 2813 | \\ int i = 0; |
| 2814 | \\ while (a > 0) { |
| 2815 | \\ a >>= 1; |
| 2816 | \\ } |
| 2817 | \\ return i; |
| 2818 | \\} |
| 2819 | , &[_][]const u8{ |
| 2820 | \\pub export fn log2(_arg_a: u32) c_int { |
| 2821 | \\ var a = _arg_a; |
| 2822 | \\ var i: c_int = 0; |
| 2823 | \\ while (a > @as(c_uint, 0)) { |
| 2824 | \\ a >>= @as(u5, 1); |
| 2825 | \\ } |
| 2826 | \\ return i; |
| 2827 | \\} |
| 2828 | }); |
| 2829 | |
| 2830 | cases.addC("compound assignment operators", |
| 2831 | \\void foo(void) { |
| 2832 | \\ int a = 0; |
| 2833 | \\ a += (a += 1); |
| 2834 | \\ a -= (a -= 1); |
| 2835 | \\ a *= (a *= 1); |
| 2836 | \\ a &= (a &= 1); |
| 2837 | \\ a |= (a |= 1); |
| 2838 | \\ a ^= (a ^= 1); |
| 2839 | \\ a >>= (a >>= 1); |
| 2840 | \\ a <<= (a <<= 1); |
| 2841 | \\} |
| 2842 | , &[_][]const u8{ |
| 2843 | \\pub export fn foo() void { |
| 2844 | \\ var a: c_int = 0; |
| 2845 | \\ a += (x: { |
| 2846 | \\ const _ref = &a; |
| 2847 | \\ _ref.* = (_ref.* + 1); |
| 2848 | \\ break :x _ref.*; |
| 2849 | \\ }); |
| 2850 | \\ a -= (x: { |
| 2851 | \\ const _ref = &a; |
| 2852 | \\ _ref.* = (_ref.* - 1); |
| 2853 | \\ break :x _ref.*; |
| 2854 | \\ }); |
| 2855 | \\ a *= (x: { |
| 2856 | \\ const _ref = &a; |
| 2857 | \\ _ref.* = (_ref.* * 1); |
| 2858 | \\ break :x _ref.*; |
| 2859 | \\ }); |
| 2860 | \\ a &= (x: { |
| 2861 | \\ const _ref = &a; |
| 2862 | \\ _ref.* = (_ref.* & 1); |
| 2863 | \\ break :x _ref.*; |
| 2864 | \\ }); |
| 2865 | \\ a |= (x: { |
| 2866 | \\ const _ref = &a; |
| 2867 | \\ _ref.* = (_ref.* | 1); |
| 2868 | \\ break :x _ref.*; |
| 2869 | \\ }); |
| 2870 | \\ a ^= (x: { |
| 2871 | \\ const _ref = &a; |
| 2872 | \\ _ref.* = (_ref.* ^ 1); |
| 2873 | \\ break :x _ref.*; |
| 2874 | \\ }); |
| 2875 | \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: { |
| 2876 | \\ const _ref = &a; |
| 2877 | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1)); |
| 2878 | \\ break :x _ref.*; |
| 2879 | \\ })); |
| 2880 | \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: { |
| 2881 | \\ const _ref = &a; |
| 2882 | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1)); |
| 2883 | \\ break :x _ref.*; |
| 2884 | \\ })); |
| 2885 | \\} |
| 2886 | }); |
| 2887 | |
| 2888 | cases.addC("compound assignment operators unsigned", |
| 2889 | \\void foo(void) { |
| 2890 | \\ unsigned a = 0; |
| 2891 | \\ a += (a += 1); |
| 2892 | \\ a -= (a -= 1); |
| 2893 | \\ a *= (a *= 1); |
| 2894 | \\ a &= (a &= 1); |
| 2895 | \\ a |= (a |= 1); |
| 2896 | \\ a ^= (a ^= 1); |
| 2897 | \\ a >>= (a >>= 1); |
| 2898 | \\ a <<= (a <<= 1); |
| 2899 | \\} |
| 2900 | , &[_][]const u8{ |
| 2901 | \\pub export fn foo() void { |
| 2902 | \\ var a: c_uint = @as(c_uint, 0); |
| 2903 | \\ a +%= (x: { |
| 2904 | \\ const _ref = &a; |
| 2905 | \\ _ref.* = (_ref.* +% @as(c_uint, 1)); |
| 2906 | \\ break :x _ref.*; |
| 2907 | \\ }); |
| 2908 | \\ a -%= (x: { |
| 2909 | \\ const _ref = &a; |
| 2910 | \\ _ref.* = (_ref.* -% @as(c_uint, 1)); |
| 2911 | \\ break :x _ref.*; |
| 2912 | \\ }); |
| 2913 | \\ a *%= (x: { |
| 2914 | \\ const _ref = &a; |
| 2915 | \\ _ref.* = (_ref.* *% @as(c_uint, 1)); |
| 2916 | \\ break :x _ref.*; |
| 2917 | \\ }); |
| 2918 | \\ a &= (x: { |
| 2919 | \\ const _ref = &a; |
| 2920 | \\ _ref.* = (_ref.* & @as(c_uint, 1)); |
| 2921 | \\ break :x _ref.*; |
| 2922 | \\ }); |
| 2923 | \\ a |= (x: { |
| 2924 | \\ const _ref = &a; |
| 2925 | \\ _ref.* = (_ref.* | @as(c_uint, 1)); |
| 2926 | \\ break :x _ref.*; |
| 2927 | \\ }); |
| 2928 | \\ a ^= (x: { |
| 2929 | \\ const _ref = &a; |
| 2930 | \\ _ref.* = (_ref.* ^ @as(c_uint, 1)); |
| 2931 | \\ break :x _ref.*; |
| 2932 | \\ }); |
| 2933 | \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 2934 | \\ const _ref = &a; |
| 2935 | \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1)); |
| 2936 | \\ break :x _ref.*; |
| 2937 | \\ })); |
| 2938 | \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: { |
| 2939 | \\ const _ref = &a; |
| 2940 | \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1)); |
| 2941 | \\ break :x _ref.*; |
| 2942 | \\ })); |
| 2943 | \\} |
| 2944 | }); |
| 2945 | |
| 2946 | cases.addC("post increment/decrement", |
| 2947 | \\void foo(void) { |
| 2948 | \\ int i = 0; |
| 2949 | \\ unsigned u = 0; |
| 2950 | \\ i++; |
| 2951 | \\ i--; |
| 2952 | \\ u++; |
| 2953 | \\ u--; |
| 2954 | \\ i = i++; |
| 2955 | \\ i = i--; |
| 2956 | \\ u = u++; |
| 2957 | \\ u = u--; |
| 2958 | \\} |
| 2959 | , &[_][]const u8{ |
| 2960 | \\pub export fn foo() void { |
| 2961 | \\ var i: c_int = 0; |
| 2962 | \\ var u: c_uint = @as(c_uint, 0); |
| 2963 | \\ i += 1; |
| 2964 | \\ i -= 1; |
| 2965 | \\ u +%= 1; |
| 2966 | \\ u -%= 1; |
| 2967 | \\ i = (x: { |
| 2968 | \\ const _ref = &i; |
| 2969 | \\ const _tmp = _ref.*; |
| 2970 | \\ _ref.* += 1; |
| 2971 | \\ break :x _tmp; |
| 2972 | \\ }); |
| 2973 | \\ i = (x: { |
| 2974 | \\ const _ref = &i; |
| 2975 | \\ const _tmp = _ref.*; |
| 2976 | \\ _ref.* -= 1; |
| 2977 | \\ break :x _tmp; |
| 2978 | \\ }); |
| 2979 | \\ u = (x: { |
| 2980 | \\ const _ref = &u; |
| 2981 | \\ const _tmp = _ref.*; |
| 2982 | \\ _ref.* +%= 1; |
| 2983 | \\ break :x _tmp; |
| 2984 | \\ }); |
| 2985 | \\ u = (x: { |
| 2986 | \\ const _ref = &u; |
| 2987 | \\ const _tmp = _ref.*; |
| 2988 | \\ _ref.* -%= 1; |
| 2989 | \\ break :x _tmp; |
| 2990 | \\ }); |
| 2991 | \\} |
| 2992 | }); |
| 2792 | 2993 | } |