Skip to content

Commit 21dc4aa

Browse files
nlw0KristofferC
authored andcommitted
Recover meta nodes in replace_code_newstyle (#31871)
Copy meta nodes from IRCode to CodeInfo (cherry picked from commit 5168e35)
1 parent da925f3 commit 21dc4aa

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

base/compiler/ssair/legacy.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
6060
ci.linetable = ir.linetable
6161
ci.ssavaluetypes = ir.types
6262
ci.ssaflags = ir.flags
63+
for metanode in ir.meta
64+
push!(ci.code, metanode)
65+
push!(ci.codelocs, 1)
66+
push!(ci.ssavaluetypes, Any)
67+
push!(ci.ssaflags, 0x00)
68+
end
6369
# Translate BB Edges to statement edges
6470
# (and undo normalization for now)
6571
for i = 1:length(ci.code)

test/compiler/ssair.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ f(a,b) = a >: b
3131
code_typed(f, Tuple{Any, Any})
3232

3333
end
34+
35+
# Issue #27104
36+
# Test whether meta nodes are still present after code optimization.
37+
let
38+
@noinline f(x, y) = x + y
39+
@test any(code_typed(f)[1][1].code) do ex
40+
Meta.isexpr(ex, :meta)
41+
end
42+
end

test/llvmpasses/noinline.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# RUN: julia --startup-file=no %s %t && llvm-link -S %t/* -o %t/module.ll
4+
# RUN: cat %t/module.ll | FileCheck %s
5+
6+
## Notes:
7+
# This script uses the `emit` function (defined llvmpasses.jl) to emit either
8+
# optimized or unoptimized LLVM IR. Each function is emitted individually and
9+
# `llvm-link` is used to create a single module that can be passed to opt.
10+
# The order in which files are emitted and linked is important since `lit` will
11+
# process the test cases in order.
12+
13+
include(joinpath("..", "testhelpers", "llvmpasses.jl"))
14+
15+
# CHECK-LABEL: @julia_simple_noinline
16+
@noinline function simple_noinline(A, B)
17+
return A + B
18+
end
19+
20+
# CHECK: attributes #{{[0-9]+}} = {{{([a-z]+ )*}} noinline {{([a-z]+ )*}}}
21+
emit(simple_noinline, Float64, Float64)

0 commit comments

Comments
 (0)