diff options
author | Ayke van Laethem <[email protected]> | 2021-03-19 12:28:50 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-03-22 11:35:06 +0100 |
commit | 71d1b70ab7be5767d83093dc6b375cd02fdf64b3 (patch) | |
tree | 47b82ae82e6b4e22aef0509bef2925d200a75cda /compiler/compiler_test.go | |
parent | 24676d43668bb4fd10d14bf179fb0985049704d1 (diff) | |
download | tinygo-71d1b70ab7be5767d83093dc6b375cd02fdf64b3.tar.gz tinygo-71d1b70ab7be5767d83093dc6b375cd02fdf64b3.zip |
compiler: only run tests on LLVM 11 or above
It's difficult to create clean test cases while remaining compatible
with multiple LLVM versions. Most test outputs are much more readable
after an instcombine pass but instcombine rules change between LLVM
versions, leading to different (but semantically equivalent) test
outputs.
This reduces the test coverage a little bit (because old LLVM versions
aren't tested as well), but it als makes it easier to add more complex
tests.
In the future it might be a good idea to make the compiler output a bit
less messy so these workarounds are not needed.
Diffstat (limited to 'compiler/compiler_test.go')
-rw-r--r-- | compiler/compiler_test.go | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 6fd1d4c50..99e14e3e7 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -4,7 +4,6 @@ import ( "flag" "go/types" "io/ioutil" - "regexp" "strconv" "strings" "testing" @@ -20,6 +19,19 @@ var flagUpdate = flag.Bool("update", false, "update tests based on test output") // Basic tests for the compiler. Build some Go files and compare the output with // the expected LLVM IR for regression testing. func TestCompiler(t *testing.T) { + // Check LLVM version. + llvmMajor, err := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0]) + if err != nil { + t.Fatal("could not parse LLVM version:", llvm.Version) + } + if llvmMajor < 11 { + // It is likely this version needs to be bumped in the future. + // The goal is to at least test the LLVM version that's used by default + // in TinyGo and (if possible without too many workarounds) also some + // previous versions. + t.Skip("compiler tests require LLVM 11 or above, got LLVM ", llvm.Version) + } + target, err := compileopts.LoadTarget("i686--linux") if err != nil { t.Fatal("failed to load target:", err) @@ -109,8 +121,6 @@ func TestCompiler(t *testing.T) { } } -var alignRegexp = regexp.MustCompile(", align [0-9]+$") - // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly // equal. That means, only relevant lines are compared (excluding comments // etc.). @@ -122,15 +132,6 @@ func fuzzyEqualIR(s1, s2 string) bool { } for i, line1 := range lines1 { line2 := lines2[i] - match1 := alignRegexp.MatchString(line1) - match2 := alignRegexp.MatchString(line2) - if match1 != match2 { - // Only one of the lines has the align keyword. Remove it. - // This is a change to make the test work in both LLVM 10 and LLVM - // 11 (LLVM 11 appears to automatically add alignment everywhere). - line1 = alignRegexp.ReplaceAllString(line1, "") - line2 = alignRegexp.ReplaceAllString(line2, "") - } if line1 != line2 { return false } @@ -144,12 +145,6 @@ func fuzzyEqualIR(s1, s2 string) bool { // stripped out. func filterIrrelevantIRLines(lines []string) []string { var out []string - llvmVersion, err := strconv.Atoi(strings.Split(llvm.Version, ".")[0]) - if err != nil { - // Note: this should never happen and if it does, it will always happen - // for a particular build because llvm.Version is a constant. - panic(err) - } for _, line := range lines { line = strings.Split(line, ";")[0] // strip out comments/info line = strings.TrimRight(line, "\r ") // drop '\r' on Windows and remove trailing spaces from comments @@ -159,15 +154,6 @@ func filterIrrelevantIRLines(lines []string) []string { if strings.HasPrefix(line, "source_filename = ") { continue } - if llvmVersion < 10 && strings.HasPrefix(line, "attributes ") { - // Ignore attribute groups. These may change between LLVM versions. - // Right now test outputs are for LLVM 10. - continue - } - if llvmVersion < 10 && strings.HasPrefix(line, "target datalayout ") { - // Ignore the target layout. This may change between LLVM versions. - continue - } out = append(out, line) } return out |