Commit e25e192
committed
Ruby: Change the CFG for while clauses
The `when` node now acts as a join point for patterns in the when
clause, with match/no-match completions. This is similar to how `or`
expressions work.
The result of this is that the `when` clause "controls" the body of the
`when`, which allows us to model barrier guards for multi-pattern when
clauses.
For this code
case x
when 1, 2
y
end
The old CFG was
x --> when --> 1 --no-match--> 2 ---no-match---> case
\ \ ^
\ \ |
\ --match----+ |
\ | |
\ | |
------match---------> y --+
The new CFG is
x --> 1 --no-match--> 2 --no-match--> [no-match] when --no-match--> case
\ \ ^
\ \ |
\ --match--> [match] when --match--> y -----+
\ /
\ /
-------match-----
i.e. all patterns flow to the `when` node, which is split based on
whether the pattern matched or not. The body of the when clause then has
a single predecessor `[match] when`, which acts as condition block that
controls `y`.1 parent a8b0d29 commit e25e192
File tree
7 files changed
+79
-41
lines changed- ruby/ql
- lib/codeql/ruby
- controlflow
- internal
- dataflow
- test/library-tests
- controlflow/graph
- dataflow/barrier-guards
7 files changed
+79
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
237 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| |||
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| |||
1397 | 1397 | | |
1398 | 1398 | | |
1399 | 1399 | | |
1400 | | - | |
| 1400 | + | |
1401 | 1401 | | |
1402 | 1402 | | |
1403 | 1403 | | |
| |||
1407 | 1407 | | |
1408 | 1408 | | |
1409 | 1409 | | |
| 1410 | + | |
| 1411 | + | |
1410 | 1412 | | |
1411 | | - | |
| 1413 | + | |
1412 | 1414 | | |
1413 | 1415 | | |
1414 | | - | |
| 1416 | + | |
| 1417 | + | |
1415 | 1418 | | |
1416 | 1419 | | |
1417 | 1420 | | |
1418 | 1421 | | |
1419 | | - | |
1420 | | - | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
1421 | 1425 | | |
1422 | 1426 | | |
1423 | 1427 | | |
1424 | 1428 | | |
1425 | 1429 | | |
1426 | 1430 | | |
1427 | 1431 | | |
1428 | | - | |
| 1432 | + | |
1429 | 1433 | | |
1430 | 1434 | | |
1431 | 1435 | | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
1432 | 1439 | | |
1433 | 1440 | | |
1434 | 1441 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
189 | 190 | | |
190 | | - | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| |||
Lines changed: 48 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
| 529 | + | |
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
535 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
536 | 539 | | |
537 | 540 | | |
538 | | - | |
539 | | - | |
| 541 | + | |
| 542 | + | |
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
| |||
569 | 572 | | |
570 | 573 | | |
571 | 574 | | |
572 | | - | |
573 | | - | |
| 575 | + | |
| 576 | + | |
574 | 577 | | |
575 | | - | |
| 578 | + | |
576 | 579 | | |
577 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
578 | 584 | | |
579 | 585 | | |
580 | 586 | | |
| |||
1826 | 1832 | | |
1827 | 1833 | | |
1828 | 1834 | | |
1829 | | - | |
| 1835 | + | |
1830 | 1836 | | |
1831 | 1837 | | |
1832 | | - | |
1833 | | - | |
1834 | | - | |
1835 | 1838 | | |
1836 | 1839 | | |
1837 | | - | |
| 1840 | + | |
1838 | 1841 | | |
1839 | | - | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
1840 | 1849 | | |
1841 | 1850 | | |
1842 | 1851 | | |
| |||
1853 | 1862 | | |
1854 | 1863 | | |
1855 | 1864 | | |
1856 | | - | |
1857 | | - | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
1858 | 1870 | | |
1859 | 1871 | | |
| 1872 | + | |
1860 | 1873 | | |
1861 | | - | |
1862 | 1874 | | |
1863 | 1875 | | |
| 1876 | + | |
1864 | 1877 | | |
1865 | | - | |
1866 | 1878 | | |
1867 | 1879 | | |
1868 | | - | |
1869 | | - | |
| 1880 | + | |
| 1881 | + | |
1870 | 1882 | | |
1871 | 1883 | | |
1872 | 1884 | | |
| |||
1901 | 1913 | | |
1902 | 1914 | | |
1903 | 1915 | | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
1904 | 1919 | | |
1905 | | - | |
| 1920 | + | |
| 1921 | + | |
1906 | 1922 | | |
1907 | 1923 | | |
1908 | 1924 | | |
1909 | 1925 | | |
1910 | 1926 | | |
1911 | | - | |
1912 | | - | |
| 1927 | + | |
| 1928 | + | |
1913 | 1929 | | |
1914 | 1930 | | |
1915 | 1931 | | |
| |||
1929 | 1945 | | |
1930 | 1946 | | |
1931 | 1947 | | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
1932 | 1951 | | |
1933 | | - | |
| 1952 | + | |
| 1953 | + | |
1934 | 1954 | | |
1935 | 1955 | | |
1936 | 1956 | | |
1937 | 1957 | | |
1938 | 1958 | | |
| 1959 | + | |
1939 | 1960 | | |
1940 | | - | |
1941 | 1961 | | |
1942 | 1962 | | |
1943 | 1963 | | |
| |||
1946 | 1966 | | |
1947 | 1967 | | |
1948 | 1968 | | |
1949 | | - | |
1950 | | - | |
| 1969 | + | |
| 1970 | + | |
1951 | 1971 | | |
1952 | 1972 | | |
1953 | 1973 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
0 commit comments