Fix assertion when returning intermediate types.

The fuzzer managed to trigger an assertion by returning an invalid type
from a void function. We were neglecting to clear out the expression
when reporting it as invalid, leaving it for `checkValid` to find later.

Change-Id: Icc152c867a3316fe994967e192601fb4d10da98f
Bug: oss-fuzz:37704
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442678
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-08-27 11:07:09 -04:00 committed by SkCQ
parent bb8cf5804c
commit 537c8a7ad5
3 changed files with 7 additions and 2 deletions

View File

@ -1 +1,3 @@
void main() { return true; }
void a() { return true; }
void b() { return b; }
void c() { return int; }

View File

@ -801,6 +801,7 @@ std::unique_ptr<Block> IRGenerator::finalizeFunction(const FunctionDeclaration&
std::move(returnStmt.expression()), returnType));
} else {
// Returning something from a function with a void return type.
returnStmt.setExpression(nullptr);
fIRGenerator->errorReporter().error(returnStmt.fOffset,
"may not return a value from a void function");
}

View File

@ -1,4 +1,6 @@
### Compilation failed:
error: 1: may not return a value from a void function
1 error
error: 2: may not return a value from a void function
error: 3: may not return a value from a void function
3 errors