@@ -1088,41 +1088,14 @@ fn run(tcx: TyCtxt) {
1088
1088
// Run dataflow solver and borrowck analysis
1089
1089
// ----------------------------------
1090
1090
1091
- // For testing, putting #[c2rust_analyze_test::fail_before_analysis] on a function marks it as
1092
- // failed at this point.
1093
- for & ldid in & all_fn_ldids {
1094
- if !util:: has_test_attr ( tcx, ldid, TestAttr :: FailBeforeAnalysis ) {
1095
- continue ;
1096
- }
1097
- gacx. mark_fn_failed (
1098
- ldid. to_def_id ( ) ,
1099
- DontRewriteFnReason :: FAKE_INVALID_FOR_TESTING ,
1100
- PanicDetail :: new ( "explicit fail_before_analysis for testing" . to_owned ( ) ) ,
1101
- ) ;
1102
- }
1103
-
1104
- // For testing, putting #[c2rust_analyze_test::force_non_null_args] on a function marks its
1105
- // arguments as `NON_NULL` and also adds `NON_NULL` to the `updates_forbidden` mask.
1106
- for & ldid in & all_fn_ldids {
1107
- if !util:: has_test_attr ( tcx, ldid, TestAttr :: ForceNonNullArgs ) {
1108
- continue ;
1109
- }
1110
-
1111
- let info = func_info. get_mut ( & ldid) . unwrap ( ) ;
1112
- let mut asn = gasn. and ( & mut info. lasn ) ;
1113
- let mut updates_forbidden = g_updates_forbidden. and_mut ( & mut info. l_updates_forbidden ) ;
1114
-
1115
- let lsig = & gacx. fn_sigs [ & ldid. to_def_id ( ) ] ;
1116
- for arg_lty in lsig. inputs . iter ( ) . copied ( ) {
1117
- for lty in arg_lty. iter ( ) {
1118
- let ptr = lty. label ;
1119
- if !ptr. is_none ( ) {
1120
- asn. perms_mut ( ) [ ptr] . insert ( PermissionSet :: NON_NULL ) ;
1121
- updates_forbidden[ ptr] . insert ( PermissionSet :: NON_NULL ) ;
1122
- }
1123
- }
1124
- }
1125
- }
1091
+ apply_test_attr_fail_before_analysis ( & mut gacx, & all_fn_ldids) ;
1092
+ apply_test_attr_force_non_null_args (
1093
+ & mut gacx,
1094
+ & all_fn_ldids,
1095
+ & mut func_info,
1096
+ & mut gasn,
1097
+ & mut g_updates_forbidden,
1098
+ ) ;
1126
1099
1127
1100
eprintln ! ( "=== ADT Metadata ===" ) ;
1128
1101
eprintln ! ( "{:?}" , gacx. adt_metadata) ;
@@ -1850,6 +1823,57 @@ fn make_sig_fixed(gasn: &mut GlobalAssignment, lsig: &LFnSig) {
1850
1823
}
1851
1824
}
1852
1825
1826
+ /// For testing, putting #[c2rust_analyze_test::fail_before_analysis] on a function marks it as
1827
+ /// failed at this point.
1828
+ fn apply_test_attr_fail_before_analysis (
1829
+ gacx : & mut GlobalAnalysisCtxt ,
1830
+ all_fn_ldids : & [ LocalDefId ] ,
1831
+ ) {
1832
+ let tcx = gacx. tcx ;
1833
+ for & ldid in all_fn_ldids {
1834
+ if !util:: has_test_attr ( tcx, ldid, TestAttr :: FailBeforeAnalysis ) {
1835
+ continue ;
1836
+ }
1837
+ gacx. mark_fn_failed (
1838
+ ldid. to_def_id ( ) ,
1839
+ DontRewriteFnReason :: FAKE_INVALID_FOR_TESTING ,
1840
+ PanicDetail :: new ( "explicit fail_before_analysis for testing" . to_owned ( ) ) ,
1841
+ ) ;
1842
+ }
1843
+ }
1844
+
1845
+ /// For testing, putting #[c2rust_analyze_test::force_non_null_args] on a function marks its
1846
+ /// arguments as `NON_NULL` and also adds `NON_NULL` to the `updates_forbidden` mask.
1847
+ fn apply_test_attr_force_non_null_args (
1848
+ gacx : & mut GlobalAnalysisCtxt ,
1849
+ all_fn_ldids : & [ LocalDefId ] ,
1850
+ func_info : & mut HashMap < LocalDefId , FuncInfo > ,
1851
+ gasn : & mut GlobalAssignment ,
1852
+ g_updates_forbidden : & mut GlobalPointerTable < PermissionSet > ,
1853
+ ) {
1854
+ let tcx = gacx. tcx ;
1855
+ for & ldid in all_fn_ldids {
1856
+ if !util:: has_test_attr ( tcx, ldid, TestAttr :: ForceNonNullArgs ) {
1857
+ continue ;
1858
+ }
1859
+
1860
+ let info = func_info. get_mut ( & ldid) . unwrap ( ) ;
1861
+ let mut asn = gasn. and ( & mut info. lasn ) ;
1862
+ let mut updates_forbidden = g_updates_forbidden. and_mut ( & mut info. l_updates_forbidden ) ;
1863
+
1864
+ let lsig = & gacx. fn_sigs [ & ldid. to_def_id ( ) ] ;
1865
+ for arg_lty in lsig. inputs . iter ( ) . copied ( ) {
1866
+ for lty in arg_lty. iter ( ) {
1867
+ let ptr = lty. label ;
1868
+ if !ptr. is_none ( ) {
1869
+ asn. perms_mut ( ) [ ptr] . insert ( PermissionSet :: NON_NULL ) ;
1870
+ updates_forbidden[ ptr] . insert ( PermissionSet :: NON_NULL ) ;
1871
+ }
1872
+ }
1873
+ }
1874
+ }
1875
+ }
1876
+
1853
1877
fn local_span ( decl : & LocalDecl ) -> Span {
1854
1878
let mut span = decl. source_info . span ;
1855
1879
if let Some ( ref info) = decl. local_info {
0 commit comments