Menu ▾ ▴

#895 hs/spe: segmentation fault when a subcircuit begins with a binned .model that is dropped (a valid deck since caa0bd377)

v1.0 (example)
open
nobody
None
5
6 days ago
6 days ago
No

Version: pre-master-48 8077acf20. ngspice-45.2 loads the deck below on x1:card.1.

Under ngbehavior=hsa, hs or spe this deck ends ngspice with a segmentation fault, exit 139, and no message.

3-model-first.cir, run as: ngspice -b -D ngbehavior=hsa 3-model-first.cir

  • a binned model is the first card of the subcircuit
    .option scale=1u
    .subckt dut d g s b l=1 w=1 nf=1
    .model card.2 nmos level=54 version=4.8 lmin=1.5e-7 lmax=1e-6 wmin=3e-6 wmax=1.01e-3
    .model card.1 nmos level=54 version=4.8 lmin=1.5e-7 lmax=1e-6 wmin=4.2e-7 wmax=3e-6
    mn d g s b card l={l} w={w} nf={nf}
    .ends dut
    vd d 0 0.9
    vg g 0 0.9
    x1 d g 0 0 dut l=0.5 w=15 nf=15
    .control
    op
    showmod m.x1.mn : model
    .endc
    .end

8077acf20, hsa, hs or spe: Segmentation fault, exit 139.
8077acf20, hsa, with -D noremcomments: x1:card.1.
ngspice-45.2, hsa: x1:card.1.
With the mn line in front of the two .model cards, 8077acf20 and 45.2 both load on x1:card.1.

The cause, from the code: under hs and spe doit() in subckt.c drops the .model cards of the bins that the size on the x line does not fit, and unlinks a card through the card before it: line_free_x(prev->nextcard, FALSE). When the card to drop is the first card of the subcircuit, prev is NULL. Here one finger is 1 um, so card.2 does not fit, and it is the first card. caa0bd377 takes the comment cards out of the deck before the subcircuits are expanded; with them left in (noremcomments) a card stands in front of the models and prev is set. I did not build the parent of caa0bd377; the noremcomments run is what points at it.

The fault itself is older. Without caa0bd377 it takes an x line with l and w for a subcircuit that has no parameter at all. That deck is in error, and ngspice-45.2 ends on it with a segmentation fault too, where it should say "Mismatch: 0 formal but 3 actual params".

Patch attached, against 8077acf20: the card is freed by itself and the deck begins behind it. With it the deck above loads on x1:card.1, and the deck of the older form gets its Mismatch message. It adds tests/regression/model/binning-model-first.cir with three decks of the valid kind; without the change ngspice ends at the first. make -k check with DISPLAY unset: 79 PASS and 1 FAIL (alter-1.cmd) before, 80 PASS and the same FAIL with the patch.

If you also take the patch of my report on wnflag and the circuit loaded before: both patches add a test to the same line of tests/regression/model/Makefile.am, so the second one needs that line merged by hand. Their changes to subckt.c do not touch.

I checked this with help from an AI coding assistant (Claude); I have NOT reviewed the results.

1 Attachments

Discussion

  • ananthsforge

    ananthsforge - 6 days ago

    test deck

     

Log in to post a comment.