diff --git a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll index b9e7d099d3c..f2da7c52f01 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll @@ -1153,9 +1153,18 @@ module GoCfg { not exists(lit.getElement(_)) and n2.isAfter(lit) ) or - // After element → lit-init → next element or After + // After element → optional lit-index → lit-init → next element or After exists(int i | - n1.isAfter(lit.getElement(i)) and n2.isAdditional(lit.getElement(i), "lit-init") + n1.isAfter(lit.getElement(i)) and + ( + n2.isAdditional(lit.getElement(i), "lit-index") + or + not exists(PreControlFlowNode idx | idx.isAdditional(lit.getElement(i), "lit-index")) and + n2.isAdditional(lit.getElement(i), "lit-init") + ) + or + n1.isAdditional(lit.getElement(i), "lit-index") and + n2.isAdditional(lit.getElement(i), "lit-init") or n1.isAdditional(lit.getElement(i), "lit-init") and ( diff --git a/go/ql/lib/semmle/go/controlflow/IR.qll b/go/ql/lib/semmle/go/controlflow/IR.qll index 91d73fe901f..651884757d0 100644 --- a/go/ql/lib/semmle/go/controlflow/IR.qll +++ b/go/ql/lib/semmle/go/controlflow/IR.qll @@ -1226,7 +1226,9 @@ module IR { ) } or /** A composite literal element target. */ - MkLiteralElementTarget(InitLiteralComponentInstruction elt) or + MkLiteralElementTarget(ControlFlow::Node write) { + write.isAdditional(any(CompositeLit lit).getAnElement(), "lit-init") + } or /** A result variable write target. */ MkResultWriteTarget(WriteResultInstruction w)