• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #38038

28 Mar 2025 06:46PM UTC coverage: 20.292% (-0.3%) from 20.564%
#38038

push

local

web-flow
lowering: Fix captured vars shadowed by an inner global declaration (#57648)

As discovered in #57547, lowering isn't resolving references to captured variables when a global of the same name is declared in any scope in the current function:

```
julia> let
            g = 1
            function f()
                let; global g = 2; end;
                return g    # g is not resolved
            end; f()
        end
ERROR: Found raw symbol in code returned from lowering. Expected all symbols to
have been resolved to GlobalRef or slots.
```

`resolve-scopes` correctly detects that we're returning the local, but scope-blocks are removed in this pass. As a result, `analyze-vars-lambda` finds more globals than `resolve-scopes` did when calling `find-global-decls` (which does not peek inside nested scopes) on `f`.  `analyze-vars-lambda` then calculates the set of captured variables in `f` to be:

```
captvars = (current_env ∩ free_vars) - (new_staticparams ∪ wrong_globals)
```

so `g` in this case is never captured.

This bug was introduced (revealed, maybe) in #57051---the whole resolution step used to happen after lowering, so lowering passes disagreeing on scopes would be less visible.

Fix: omit globals from the free variable list in `analyze-vars-lambda` in the first place.  This way we don't need to call the scope-block-dependent `find-global-decls`.

9941 of 48990 relevant lines covered (20.29%)

99223.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.31
/stdlib/CompilerSupportLibraries_jll/src/CompilerSupportLibraries_jll.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
## dummy stub for https://github.com/JuliaBinaryWrappers/CompilerSupportLibraries_jll.jl
4

5
baremodule CompilerSupportLibraries_jll
6
using Base, Libdl, Base.BinaryPlatforms
7

8
export libgfortran, libstdcxx, libgomp, libatomic, libgcc_s
9

10
# These get calculated in __init__()
11
const PATH = Ref("")
12
const PATH_list = String[]
13
const LIBPATH = Ref("")
14
const LIBPATH_list = String[]
15
artifact_dir::String = ""
16
libgcc_s_path::String = ""
17
libgfortran_path::String = ""
18
libstdcxx_path::String = ""
19
libgomp_path::String = ""
20

21
if Sys.iswindows()
22
    const _libatomic_path = BundledLazyLibraryPath("libatomic-1.dll")
23
    const _libquadmath_path = BundledLazyLibraryPath("libquadmath-0.dll")
24
    if arch(HostPlatform()) == "x86_64"
25
        const _libgcc_s_path = BundledLazyLibraryPath("libgcc_s_seh-1.dll")
26
    else
27
        const _libgcc_s_path = BundledLazyLibraryPath("libgcc_s_sjlj-1.dll")
28
    end
29
    const _libgfortran_path = BundledLazyLibraryPath(string("libgfortran-", libgfortran_version(HostPlatform()).major, ".dll"))
30
    const _libstdcxx_path = BundledLazyLibraryPath("libstdc++-6.dll")
31
    const _libgomp_path = BundledLazyLibraryPath("libgomp-1.dll")
32
    const _libssp_path = BundledLazyLibraryPath("libssp-0.dll")
33
elseif Sys.isapple()
34
    const _libatomic_path = BundledLazyLibraryPath("libatomic.1.dylib")
35
    const _libquadmath_path = BundledLazyLibraryPath("libquadmath.0.dylib")
36
    if arch(HostPlatform()) == "aarch64" || libgfortran_version(HostPlatform()) == v"5"
37
        const _libgcc_s_path = BundledLazyLibraryPath("libgcc_s.1.1.dylib")
38
    else
39
        const _libgcc_s_path = BundledLazyLibraryPath("libgcc_s.1.dylib")
40
    end
41
    const _libgfortran_path = BundledLazyLibraryPath(string("libgfortran.", libgfortran_version(HostPlatform()).major, ".dylib"))
42
    const _libstdcxx_path = BundledLazyLibraryPath("libstdc++.6.dylib")
43
    const _libgomp_path = BundledLazyLibraryPath("libgomp.1.dylib")
44
    const _libssp_path = BundledLazyLibraryPath("libssp.0.dylib")
45
else
46
    if Sys.isfreebsd()
47
        const _libatomic_path = BundledLazyLibraryPath("libatomic.so.3")
48
    else
49
        const _libatomic_path = BundledLazyLibraryPath("libatomic.so.1")
50
    end
51
    const _libgcc_s_path = BundledLazyLibraryPath("libgcc_s.so.1")
52
    const _libgfortran_path = BundledLazyLibraryPath(string("libgfortran.so.", libgfortran_version(HostPlatform()).major))
53
    const _libstdcxx_path = BundledLazyLibraryPath("libstdc++.so.6")
54
    const _libgomp_path = BundledLazyLibraryPath("libgomp.so.1")
55
    if libc(HostPlatform()) != "musl"
56
        const _libssp_path = BundledLazyLibraryPath("libssp.so.0")
57
    end
58
    if arch(HostPlatform()) ∈ ("x86_64", "i686")
59
        const _libquadmath_path = BundledLazyLibraryPath("libquadmath.so.0")
60
    end
61
end
62

63
if @isdefined(_libatomic_path)
64
    const libatomic = LazyLibrary(_libatomic_path)
65
end
66
const libgcc_s = LazyLibrary(_libgcc_s_path)
67
libgfortran_deps = [libgcc_s]
68
if @isdefined _libquadmath_path
69
    const libquadmath = LazyLibrary(_libquadmath_path)
70
    push!(libgfortran_deps, libquadmath)
71
end
72
const libgfortran = LazyLibrary(_libgfortran_path, dependencies=libgfortran_deps)
73
const libstdcxx = LazyLibrary(_libstdcxx_path, dependencies=[libgcc_s])
74
const libgomp = LazyLibrary(_libgomp_path)
75
if @isdefined _libssp_path
76
    const libssp = LazyLibrary(_libssp_path)
77
end
78

79
# Conform to LazyJLLWrappers API
80
function eager_mode()
×
81
    if @isdefined(libatomic)
×
82
        dlopen(libatomic)
×
83
    end
84
    dlopen(libgcc_s)
×
85
    dlopen(libgomp)
×
86
    if @isdefined libquadmath
×
87
        dlopen(libquadmath)
×
88
    end
89
    if @isdefined libssp
×
90
        dlopen(libssp)
×
91
    end
92
    dlopen(libgfortran)
×
93
    dlopen(libstdcxx)
×
94
end
95
is_available() = true
×
96

97
function __init__()
2✔
98
    if @isdefined _libatomic_path
×
99
        global libatomic_path = string(_libatomic_path)
4✔
100
    end
101
    global libgcc_s_path = string(_libgcc_s_path)
4✔
102
    global libgomp_path = string(_libgomp_path)
4✔
103
    if @isdefined _libquadmath_path
×
104
        global libquadmath_path = string(_libquadmath_path)
4✔
105
    end
106
    if @isdefined _libssp_path
×
107
        global libssp_path = string(_libssp_path)
4✔
108
    end
109
    global libgfortran_path = string(_libgfortran_path)
4✔
110
    global libstdcxx_path = string(_libstdcxx_path)
4✔
111
    global artifact_dir = dirname(Sys.BINDIR)
2✔
112
    LIBPATH[] = dirname(libgcc_s_path)
2✔
113
    push!(LIBPATH_list, LIBPATH[])
2✔
114
end
115

116
end  # module CompilerSupportLibraries_jll
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc