aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-03-06 16:09:41 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-03-08 10:56:47 +0000
commit8e75c913b6f9b09cab2ad31fd7d66ea0d1703de8 (patch)
tree08556bc4e03b3550324770d80f9a02b057b12ad4 /prog/encoding.go
parent4097c8d7a8596ddbc9a9db7b7f39c5cbdb1bd742 (diff)
prog: auto-set proper conditional fields in Deserialize()
Treat all default union arguments as transient and reevaluate them after the call was fully parsed. Before conditional field patching, we do need to have performed arg validation, which also reevaluates conditions. To break the cycle, make validation configurable.
Diffstat (limited to 'prog/encoding.go')
-rw-r--r--prog/encoding.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index b5d5114ca..e925e7918 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -257,9 +257,13 @@ func (target *Target) Deserialize(data []byte, mode DeserializeMode) (*Prog, err
// This validation is done even in non-debug mode because deserialization
// procedure does not catch all bugs (e.g. mismatched types).
// And we can receive bad programs from corpus and hub.
- if err := prog.validate(); err != nil {
+ if err := prog.validateWithOpts(validationOptions{
+ // Don't validate auto-set conditional fields. We'll patch them later.
+ ignoreTransient: true,
+ }); err != nil {
return nil, err
}
+ p.fixupConditionals(prog)
if p.autos != nil {
p.fixupAutos(prog)
}
@@ -1154,6 +1158,13 @@ func (p *parser) fixupAutos(prog *Prog) {
}
}
+func (p *parser) fixupConditionals(prog *Prog) {
+ for _, c := range prog.Calls {
+ // Only overwrite transient union fields.
+ c.setDefaultConditions(p.target, true)
+ }
+}
+
func (p *parser) Scan() bool {
if p.e != nil || len(p.data) == 0 {
return false