From b1789179d584c064638f72567b383341674ce903 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Wed, 22 Jul 2026 07:18:50 +0800 Subject: [PATCH] fix(debug): ignore storage-free Python variables --- cl/compile_test.go | 7 +++++++ ssa/di.go | 5 +++++ ssa/di_debug_test.go | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/cl/compile_test.go b/cl/compile_test.go index 108cbb7353..150ff0a841 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -412,6 +412,13 @@ func TestRunAndTestFromTestpy(t *testing.T) { cltest.RunAndTestFromDir(t, "", "./_testpy", nil) } +func TestRunAndTestFromTestpyDWARF(t *testing.T) { + conf := build.NewDefaultConf(build.ModeRun) + conf.LinkOptions.DWARF = build.DWARFPreserve + cltest.RunAndTestFromDir(t, "", "./_testpy", nil, + cltest.WithRunConfig(conf), cltest.WithIRCheck(false)) +} + func TestRunAndTestFromTestlibgo(t *testing.T) { cltest.RunAndTestFromDir(t, "", "./_testlibgo", nil) } diff --git a/ssa/di.go b/ssa/di.go index 18058eeebe..f046d8601a 100644 --- a/ssa/di.go +++ b/ssa/di.go @@ -769,6 +769,11 @@ const ( ) func (b Builder) DIGlobal(v Expr, name string, pos token.Position) { + // Frontend pseudo-variables, such as Python module attributes, have no + // native storage to describe or attach metadata to. + if v.impl.IsNil() { + return + } if _, ok := b.Pkg.glbDbgVars[v]; ok { return } diff --git a/ssa/di_debug_test.go b/ssa/di_debug_test.go index aebb9d016f..5732096564 100644 --- a/ssa/di_debug_test.go +++ b/ssa/di_debug_test.go @@ -166,6 +166,11 @@ type Shape struct { } } +func TestDIGlobalIgnoresStorageLessFrontendVariable(t *testing.T) { + var builder Builder + builder.DIGlobal(pyVarExpr(Nil, "attribute"), "module.attribute", token.Position{}) +} + func newDebugRuntimePackage() *types.Package { pkg := types.NewPackage(PkgRuntime, "runtime") unsafePointer := types.Typ[types.UnsafePointer]