From 73ffb77b2dfb10cb12bd626d8e8b6854fde2f913 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:04:39 +0000 Subject: [PATCH 1/4] Initial plan From 34228618be279da43a0e62140a5fb43b00d20266 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:13:29 +0000 Subject: [PATCH 2/4] Replace list computation + empty check with short-circuiting alternatives Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com> --- src/check.ml | 8 ++++---- src/cil.ml | 2 +- src/frontc/cabs2cil.ml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/check.ml b/src/check.ml index d8ff57f4f..e7480baa0 100644 --- a/src/check.ml +++ b/src/check.ml @@ -583,9 +583,9 @@ and checkExp (isconst: bool) (e: exp) : typ = | AddrOfLabel (gref) -> begin (* Find a label *) let lab = - match List.filter (function Label _ -> true | _ -> false) + match List.find_opt (function Label _ -> true | _ -> false) !gref.labels with - Label (lab, _, _) :: _ -> lab + Some (Label (lab, _, _)) -> lab | _ -> ignore (warn "Address of label to block without a label"); "" @@ -748,9 +748,9 @@ and checkStmt (s: stmt) = currentLoc := l; (* Find a label *) let lab = - match List.filter (function Label _ -> true | _ -> false) + match List.find_opt (function Label _ -> true | _ -> false) !gref.labels with - Label (lab, _, _) :: _ -> lab + Some (Label (lab, _, _)) -> lab | _ -> ignore (warn "Goto to block without a label"); "" diff --git a/src/cil.ml b/src/cil.ml index 5b2d87db3..54d82e327 100755 --- a/src/cil.ml +++ b/src/cil.ml @@ -1427,7 +1427,7 @@ and filterAttributes (s: string) (al: attribute list) : attribute list = (* sm: *) let hasAttribute s al = - (filterAttributes s al <> []) + List.exists (fun (Attr(an, _)) -> an = s) al type attributeClass = diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index b4366dbb6..fd155b1c4 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -5637,10 +5637,10 @@ and doInit (* We have a designator *) | _, (what, ie) :: restil when what != A.NEXT_INIT -> let rec unrollDesignatorForNestedAnonymous (comp: compinfo) (designator: string) (whatnext: initwhat) = - let own_field = List.filter (fun fld -> fld.fname = designator) comp.cfields in + let own_field = List.find_opt (fun fld -> fld.fname = designator) comp.cfields in match own_field with - | fld :: _ -> (true, Some(A.INFIELD_INIT (designator, whatnext))) - | [] -> + | Some _ -> (true, Some(A.INFIELD_INIT (designator, whatnext))) + | None -> let anonymous_compounds = List.filter_map (fun f -> (* f.ftype need not be unrolled here, inner anonymous struct cannot be typdef'ed *) match f.ftype with From b8ac672005e4a6467f901cb677f155bac8598881 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:18:07 +0000 Subject: [PATCH 3/4] Revert src/cil.ml changes Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com> --- src/cil.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cil.ml b/src/cil.ml index 54d82e327..5b2d87db3 100755 --- a/src/cil.ml +++ b/src/cil.ml @@ -1427,7 +1427,7 @@ and filterAttributes (s: string) (al: attribute list) : attribute list = (* sm: *) let hasAttribute s al = - List.exists (fun (Attr(an, _)) -> an = s) al + (filterAttributes s al <> []) type attributeClass = From 5550d177d9dbdfe8f7a8002b1d944901130375ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 08:37:17 +0000 Subject: [PATCH 4/4] Use List.exists in unrollDesignatorForNestedAnonymous Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com> --- src/frontc/cabs2cil.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index fd155b1c4..66716e2ff 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -5637,10 +5637,9 @@ and doInit (* We have a designator *) | _, (what, ie) :: restil when what != A.NEXT_INIT -> let rec unrollDesignatorForNestedAnonymous (comp: compinfo) (designator: string) (whatnext: initwhat) = - let own_field = List.find_opt (fun fld -> fld.fname = designator) comp.cfields in - match own_field with - | Some _ -> (true, Some(A.INFIELD_INIT (designator, whatnext))) - | None -> + if List.exists (fun fld -> fld.fname = designator) comp.cfields then + (true, Some(A.INFIELD_INIT (designator, whatnext))) + else let anonymous_compounds = List.filter_map (fun f -> (* f.ftype need not be unrolled here, inner anonymous struct cannot be typdef'ed *) match f.ftype with