From b61751e4298401150661a20bf689c45e6065b58a Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 9 Apr 2021 00:32:58 +0200 Subject: [PATCH] compiler: check for errors Some errors were generated but never returned or never checked in the test function. That's a problem. Therefore this commit fixes this oversight (by me). --- compiler/compiler.go | 2 +- compiler/compiler_test.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index d652f540..acf85cd8 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -298,7 +298,7 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package, c.dibuilder.Finalize() } - return c.mod, nil + return c.mod, c.diagnostics } // getLLVMRuntimeType obtains a named type from the runtime package and returns diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 5f2d18f4..202ed16f 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -84,11 +84,16 @@ func TestCompiler(t *testing.T) { mod, errs := CompilePackage(testCase, pkg, program.Package(pkg.Pkg), machine, compilerConfig, false) if errs != nil { for _, err := range errs { - t.Log("error:", err) + t.Error(err) } return } + err = llvm.VerifyModule(mod, llvm.PrintMessageAction) + if err != nil { + t.Error(err) + } + // Optimize IR a little. funcPasses := llvm.NewFunctionPassManagerForModule(mod) defer funcPasses.Dispose()