tests: normalize LLVM IR when updating goldens

This commit is contained in:
Jake Bailey
2026-08-06 22:30:31 -07:00
committed by Damian Gryski
parent c4219439eb
commit 570a3deac2
5 changed files with 68 additions and 66 deletions
+3 -4
View File
@@ -115,7 +115,7 @@ func TestCompiler(t *testing.T) {
// Update test if needed. Do not check the result.
if *flagUpdate {
err := os.WriteFile(outPath, []byte(mod.String()), 0666)
err := os.WriteFile(outPath, []byte(normalizeIR(mod.String())), 0666)
if err != nil {
t.Error("failed to write updated output file:", err)
}
@@ -174,9 +174,8 @@ func TestOptimizedLargeAggregateABI(t *testing.T) {
}
}
// normalizeIR canonicalizes LLVM IR so a single golden file keeps matching
// across LLVM versions. Golden files are written against LLVM <21; newer LLVM
// prints some attributes differently.
// normalizeIR canonicalizes LLVM-version-specific IR spellings for comparison
// and when regenerating golden files.
func normalizeIR(s string) string {
// Golden files are written using the pre-LLVM21 'nocapture' spelling,
// which LLVM printed before any co-occurring attribute such as