Fix assertion when calling a built-in function at global scope.

The fuzzer invented a much more elaborate example, but I was able to
winnow it down to a simple otherwise-normal test case. This also fixes
a latent DSL bug; DSL functions were not updating the list of referenced
intrinsics, so the compiler might emit finished programs that called
built-in functions that didn't exist in the code.

Change-Id: I095bb566b9db9f87cbe9460732c300b7973eb112
Bug: oss-fuzz:37659
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442325
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/dsl/DSLFunction.cpp b/src/sksl/dsl/DSLFunction.cpp
index 21305c1..18a8892 100644
--- a/src/sksl/dsl/DSLFunction.cpp
+++ b/src/sksl/dsl/DSLFunction.cpp
@@ -89,9 +89,12 @@
     }
     SkASSERTF(!fDecl->definition(), "function '%s' already defined", fDecl->description().c_str());
     std::unique_ptr<Block> body = block.release();
-    body = DSLWriter::IRGenerator().finalizeFunction(*fDecl, std::move(body));
+    IntrinsicSet referencedIntrinsics;
+    body = DSLWriter::IRGenerator().finalizeFunction(*fDecl, std::move(body),
+                                                     &referencedIntrinsics);
     auto function = std::make_unique<SkSL::FunctionDefinition>(/*offset=*/-1, fDecl,
-                                                               /*builtin=*/false, std::move(body));
+                                                               /*builtin=*/false, std::move(body),
+                                                               std::move(referencedIntrinsics));
     DSLWriter::ReportErrors();
     fDecl->fDefinition = function.get();
     DSLWriter::ProgramElements().push_back(std::move(function));