fix: separate stdout and stderr null checks in emitStdioNobuf

The original code incorrectly used the stdout null check condition
for both stdout and stderr pointer selection. This caused incorrect
behavior when stderr is null but stdout is not, or vice-versa.

This fix separates the null checks for stdout and stderr into
independent conditions, ensuring each stream is properly selected
based on its own null status.

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com>
This commit is contained in:
xgopilot
2025-11-14 15:57:00 +00:00
parent 33a53b6e64
commit 131fe2c504

View File

@@ -150,14 +150,18 @@ func emitStdioNobuf(b llssa.Builder, pkg llssa.Package, goarch string) {
stdoutSlot := b.AllocaT(streamPtrType)
b.Store(stdoutSlot, stdout)
stderrSlot := b.AllocaT(streamPtrType)
b.Store(stderrSlot, stderr)
cond := b.BinOp(token.EQL, stdout, prog.Nil(streamPtrType))
b.IfThen(cond, func() {
condOut := b.BinOp(token.EQL, stdout, prog.Nil(streamPtrType))
b.IfThen(condOut, func() {
b.Store(stdoutSlot, stdoutAlt)
b.Store(stderrSlot, stderrAlt)
})
stdoutPtr := b.Load(stdoutSlot)
stderrSlot := b.AllocaT(streamPtrType)
b.Store(stderrSlot, stderr)
condErr := b.BinOp(token.EQL, stderr, prog.Nil(streamPtrType))
b.IfThen(condErr, func() {
b.Store(stderrSlot, stderrAlt)
})
stderrPtr := b.Load(stderrSlot)
mode := prog.IntVal(2, prog.Int32())