Have cgen zero-initialize all local variables

This commit is contained in:
Nigel Tao committed 2018-12-27 11:54:33 +11:00
1 parent 6dc68950c0
commit 983cebd893
5 files changed
+183 -335

No files matched your search

+18 -7
View File
@@ -344,20 +344,31 @@ func (g *gen) writeResumeSuspend(b *buffer, f *funk, suspend bool, initBoolTyped
return nil
}
func (g *gen) writeVars(b *buffer, f *funk, skipPointerTypes bool, skipNonresumable bool) error {
func (g *gen) writeVars(b *buffer, f *funk, inStructDecl bool) error {
for _, n := range f.varList {
typ := n.XType()
if skipPointerTypes && typ.HasPointers() {
continue
}
if skipNonresumable && (f.varResumables == nil || !f.varResumables[n.Name()]) {
continue
if inStructDecl {
if typ.HasPointers() || f.varResumables == nil || !f.varResumables[n.Name()] {
continue
}
}
name := n.Name().Str(g.tm)
if err := g.writeCTypeName(b, typ, vPrefix, name); err != nil {
return err
}
b.writes(";\n")
if inStructDecl {
b.writes(";\n")
} else if typ.IsNumType() {
b.writes(" = 0;\n")
} else if typ.IsBool() {
b.writes(" = false;\n")
} else if typ.IsStatus() {
b.writes(" = NULL;\n")
} else {
b.writes(" = {};\n")
}
if typ.IsIOType() {
b.printf("wuffs_base__io_buffer %s%s;\n", uPrefix, name)
preName := vPrefix + name