From 7de7a5ecf43a5c41b5170d0cb70cb744fdf9de9f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 26 Nov 2024 11:36:41 +0100 Subject: pkg/compiler: allow manual consts to override auto-extracted consts Currently if const values in 2 .const files have different value, the compiler produces an error. This is problematic for auto-extacted consts since we extract them for only 1 arch now. So if a const has different values for different arches, auto-extacted consts may not reflect that, and we can get a mismatch with manual descriptions that has correct values for all arches. So if both manual and auto-extacted consts have different values, silently prefer the manual ones. I've tried to do some whitelisting of consts during auto-extaction, but the list is large and changing over time. This solution is not perfect since the manual descriptions may have a bug, and the mismatch is actually pointing to that bug. Maybe in future we could extract for all arches separately, or do something else. But let's do this for now. --- pkg/compiler/compiler_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pkg/compiler/compiler_test.go') diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index f43b2ccb3..711567163 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -137,6 +137,27 @@ func TestData(t *testing.T) { } } +func TestAutoConsts(t *testing.T) { + t.Parallel() + eh := func(pos ast.Pos, msg string) { + t.Errorf("%v: %v", pos, msg) + } + desc := ast.ParseGlob(filepath.Join("testdata", "auto*.txt"), eh) + if desc == nil { + t.Fatalf("parsing failed") + } + constFile := DeserializeConstFile(filepath.Join("testdata", "auto*.txt.const"), eh) + if constFile == nil { + t.Fatalf("const loading failed") + } + target := targets.List[targets.TestOS][targets.TestArch64] + consts := constFile.Arch(targets.TestArch64) + prog := Compile(desc, consts, target, eh) + if prog == nil { + t.Fatalf("compilation failed") + } +} + func TestFuzz(t *testing.T) { t.Parallel() for _, data := range []string{ -- cgit mrf-deployment