fortrangoingonforty/armfortas / 48f43d6

Browse files

Fix root CI regressions

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
48f43d634af91dc5c63b223a452051abf6c7b643
Parents
54e88fa
Tree
0a4bd08

5 changed files

StatusFile+-
M src/ir/lower.rs 24 13
M src/parser/unit.rs 2 6
M src/sema/resolve.rs 2 2
M src/sema/type_layout.rs 4 4
M tests/licm_lsf_audit_29_11.rs 35 2
src/ir/lower.rsmodified
@@ -18,6 +18,8 @@ use std::collections::{HashMap, HashSet};
1818
 use std::io::Write;
1919
 use std::rc::Rc;
2020
 
21
+type AmbiguousUseWarnings = Rc<RefCell<HashSet<(String, String, String)>>>;
22
+
2123
 /// Maximum array rank (Fortran allows up to 15).
2224
 const MAX_RANK: usize = 15;
2325
 
@@ -164,7 +166,7 @@ struct LowerCtx<'a> {
164166
     /// install_globals_as_locals. Large fortsh units can otherwise print the
165167
     /// exact same ambiguity hundreds or thousands of times while lowering each
166168
     /// contained procedure separately.
167
-    ambiguous_use_warnings: Rc<RefCell<HashSet<(String, String, String)>>>,
169
+    ambiguous_use_warnings: AmbiguousUseWarnings,
168170
 }
169171
 
170172
 impl<'a> LowerCtx<'a> {
@@ -179,7 +181,7 @@ impl<'a> LowerCtx<'a> {
179181
         elemental_funcs: &'a HashSet<String>,
180182
         char_len_star_params: &'a HashMap<String, Vec<bool>>,
181183
         contained_host_refs: &'a HashMap<String, Vec<String>>,
182
-        ambiguous_use_warnings: Rc<RefCell<HashSet<(String, String, String)>>>,
184
+        ambiguous_use_warnings: AmbiguousUseWarnings,
183185
     ) -> Self {
184186
         Self {
185187
             locals: HashMap::new(),
@@ -287,8 +289,7 @@ pub fn lower_file(
287289
 ) -> (Module, HashMap<(String, String), ModuleGlobalInfo>) {
288290
     let mut module = Module::new("main".into());
289291
     let mut globals: HashMap<(String, String), ModuleGlobalInfo> = external_globals;
290
-    let ambiguous_use_warnings: Rc<RefCell<HashSet<(String, String, String)>>> =
291
-        Rc::new(RefCell::new(HashSet::new()));
292
+    let ambiguous_use_warnings: AmbiguousUseWarnings = Rc::new(RefCell::new(HashSet::new()));
292293
 
293294
     // Pass 1: collect module-level variables.  Submodule decls are
294295
     // installed under their parent module's name so the submodule's
@@ -2554,7 +2555,7 @@ fn lower_unit(
25542555
     // names it reads or writes. Drives both callee signature
25552556
     // (hidden trailing pointer params) and call-site arg list.
25562557
     contained_host_refs: &HashMap<String, Vec<String>>,
2557
-    ambiguous_use_warnings: &Rc<RefCell<HashSet<(String, String, String)>>>,
2558
+    ambiguous_use_warnings: &AmbiguousUseWarnings,
25582559
     internal_only: bool,
25592560
 ) {
25602561
     match &unit.node {
@@ -4796,7 +4797,7 @@ fn install_globals_as_locals(
47964797
     required_names: Option<&HashSet<String>>,
47974798
     host_module: Option<&str>,
47984799
     st: &SymbolTable,
4799
-    ambiguous_use_warnings: &Rc<RefCell<HashSet<(String, String, String)>>>,
4800
+    ambiguous_use_warnings: &AmbiguousUseWarnings,
48004801
 ) {
48014802
     use crate::ast::decl::OnlyItem;
48024803
 
@@ -13368,7 +13369,6 @@ fn lower_stmt(b: &mut FuncBuilder, ctx: &mut LowerCtx, stmt: &SpannedStmt) {
1336813369
                                                     vec![dest_ptr, dest_len, src_ptr, src_len],
1336913370
                                                     IrType::Void,
1337013371
                                                 );
13371
-                                                return;
1337213372
                                             }
1337313373
                                         }
1337413374
                                     }
@@ -13448,7 +13448,6 @@ fn lower_stmt(b: &mut FuncBuilder, ctx: &mut LowerCtx, stmt: &SpannedStmt) {
1344813448
                                                     vec![dest_ptr, dest_len, src_ptr, src_len],
1344913449
                                                     IrType::Void,
1345013450
                                                 );
13451
-                                                return;
1345213451
                                             }
1345313452
                                         }
1345413453
                                     }
@@ -16129,7 +16128,7 @@ fn lower_stmt(b: &mut FuncBuilder, ctx: &mut LowerCtx, stmt: &SpannedStmt) {
1612916128
                 if !tgt_field.pointer {
1613016129
                     return;
1613116130
                 }
16132
-                if is_deferred_char_component_field(&tgt_field) {
16131
+                if is_deferred_char_component_field(tgt_field) {
1613316132
                     if let Expr::FunctionCall { callee, .. } = &value.node {
1613416133
                         if let Expr::Name { name } = &callee.node {
1613516134
                             if name.eq_ignore_ascii_case("null") {
@@ -20335,8 +20334,14 @@ fn whole_array_expr_local_info(
2033520334
                 .filter(|info| local_is_array_like(info))
2033620335
                 .cloned()
2033720336
         }
20338
-        Expr::ComponentAccess { .. } => component_intrinsic_local_info(b, locals, expr, st, type_layouts)
20339
-            .filter(|info| local_is_array_like(info)),
20337
+        Expr::ComponentAccess { .. } => component_intrinsic_local_info(
20338
+            b,
20339
+            locals,
20340
+            expr,
20341
+            st,
20342
+            type_layouts,
20343
+        )
20344
+        .filter(local_is_array_like),
2034020345
         _ => None,
2034120346
     }
2034220347
 }
@@ -21977,7 +21982,7 @@ fn component_intrinsic_local_info(
2197721982
     tl: &crate::sema::type_layout::TypeLayoutRegistry,
2197821983
 ) -> Option<LocalInfo> {
2197921984
     let (field_ptr, field) = resolve_component_field_access(b, locals, expr, st, tl)?;
21980
-    if field.size == 384 && (field.allocatable || field.pointer) {
21985
+    if field_uses_array_descriptor(&field) {
2198121986
         return Some(LocalInfo {
2198221987
             addr: field_ptr,
2198321988
             ty: field_storage_ir_type(&field, tl),
@@ -22908,6 +22913,12 @@ fn field_storage_ir_type(
2290822913
     }
2290922914
 }
2291022915
 
22916
+fn field_uses_array_descriptor(field: &crate::sema::type_layout::FieldLayout) -> bool {
22917
+    field.size == 384
22918
+        && (field.allocatable || field.pointer)
22919
+        && (field.declared_array || !field.dims.is_empty())
22920
+}
22921
+
2291122922
 fn component_array_local_info(
2291222923
     b: &mut FuncBuilder,
2291322924
     locals: &HashMap<String, LocalInfo>,
@@ -22916,7 +22927,7 @@ fn component_array_local_info(
2291622927
     tl: &crate::sema::type_layout::TypeLayoutRegistry,
2291722928
 ) -> Option<LocalInfo> {
2291822929
     let (field_ptr, field) = resolve_component_field_access(b, locals, expr, st, tl)?;
22919
-    if field.size != 384 || !(field.allocatable || field.pointer) {
22930
+    if !field_uses_array_descriptor(&field) {
2292022931
         return None;
2292122932
     }
2292222933
     Some(LocalInfo {
src/parser/unit.rsmodified
@@ -731,12 +731,8 @@ impl<'a> Parser<'a> {
731731
                         self.advance();
732732
                     } // consume ::
733733
                     let mut names = Vec::new();
734
-                    loop {
735
-                        if let Some(name) = self.parse_access_list_item()? {
736
-                            names.push(name);
737
-                        } else {
738
-                            break;
739
-                        }
734
+                    while let Some(name) = self.parse_access_list_item()? {
735
+                        names.push(name);
740736
                         if !self.eat(&TokenKind::Comma) {
741737
                             break;
742738
                         }
src/sema/resolve.rsmodified
@@ -943,7 +943,7 @@ fn find_unit_scope(st: &SymbolTable, parent_scope: ScopeId, unit: &ProgramUnit)
943943
 fn exported_const_int_params(
944944
     st: &SymbolTable,
945945
     scope_id: ScopeId,
946
-    visible_cache: &mut HashMap<ScopeId, HashMap<String, i64>>,
946
+    _visible_cache: &mut HashMap<ScopeId, HashMap<String, i64>>,
947947
     exported_cache: &mut HashMap<ScopeId, HashMap<String, i64>>,
948948
 ) -> HashMap<String, i64> {
949949
     if let Some(cached) = exported_cache.get(&scope_id) {
@@ -986,7 +986,7 @@ fn exported_const_int_params(
986986
             continue;
987987
         }
988988
         for (name, value) in
989
-            exported_const_int_params(st, assoc.source_scope, visible_cache, exported_cache)
989
+            exported_const_int_params(st, assoc.source_scope, _visible_cache, exported_cache)
990990
         {
991991
             out.entry(name).or_insert(value);
992992
         }
src/sema/type_layout.rsmodified
@@ -237,10 +237,10 @@ fn eval_const_logical_expr(expr: &crate::ast::expr::SpannedExpr) -> Option<bool>
237237
     match &expr.node {
238238
         Expr::LogicalLiteral { value, .. } => Some(*value),
239239
         Expr::ParenExpr { inner } => eval_const_logical_expr(inner),
240
-        Expr::UnaryOp { op, operand } => match op {
241
-            crate::ast::expr::UnaryOp::Not => eval_const_logical_expr(operand).map(|v| !v),
242
-            _ => None,
243
-        },
240
+        Expr::UnaryOp {
241
+            op: crate::ast::expr::UnaryOp::Not,
242
+            operand,
243
+        } => eval_const_logical_expr(operand).map(|v| !v),
244244
         _ => None,
245245
     }
246246
 }
tests/licm_lsf_audit_29_11.rsmodified
@@ -96,6 +96,39 @@ fn block_section<'a>(func_section: &'a str, prefix: &str) -> &'a str {
9696
     &func_section[start..end]
9797
 }
9898
 
99
+fn last_block_section<'a>(func_section: &'a str, prefix: &str) -> &'a str {
100
+    let mut starts = Vec::new();
101
+
102
+    for (idx, _line) in func_section.match_indices('\n') {
103
+        let line_start = idx + 1;
104
+        let tail = &func_section[line_start..];
105
+        let line_text = tail.split_once('\n').map(|(line, _)| line).unwrap_or(tail);
106
+        if line_text.starts_with("    ")
107
+            && !line_text.starts_with("      ")
108
+            && line_text[4..].starts_with(prefix)
109
+        {
110
+            starts.push(line_start);
111
+        }
112
+    }
113
+
114
+    let start = *starts
115
+        .last()
116
+        .unwrap_or_else(|| panic!("missing block with prefix {}", prefix));
117
+    let tail = &func_section[start..];
118
+    let end = tail
119
+        .match_indices('\n')
120
+        .find_map(|(idx, _)| {
121
+            let line_start = idx + 1;
122
+            let rest = &tail[line_start..];
123
+            let line_text = rest.split_once('\n').map(|(line, _)| line).unwrap_or(rest);
124
+            ((line_text.starts_with("    ") && !line_text.starts_with("      "))
125
+                || line_text == "  }")
126
+                .then_some(idx)
127
+        })
128
+        .unwrap_or(tail.len());
129
+    &tail[..end]
130
+}
131
+
99132
 fn tail_after<'a>(text: &'a str, needle: &str) -> &'a str {
100133
     let start = text
101134
         .find(needle)
@@ -233,8 +266,8 @@ fn o2_forwards_branch_join_reuse_across_noalias_side_call() {
233266
 
234267
     let raw_branchy = function_section(&raw_ir, helper_names[2]);
235268
     let opt_branchy = function_section(&opt_ir, helper_names[2]);
236
-    let raw_join = block_section(raw_branchy, "if_end_9");
237
-    let opt_join = block_section(opt_branchy, "if_end_9");
269
+    let raw_join = last_block_section(raw_branchy, "if_end_");
270
+    let opt_join = last_block_section(opt_branchy, "if_end_");
238271
 
239272
     assert!(
240273
         raw_join.contains("gep") && raw_join.contains("load"),