Skip to content

Commit 5168e35

Browse files
nlw0vchuravy
authored andcommitted
Recover meta nodes in replace_code_newstyle (#31871)
Copy meta nodes from IRCode to CodeInfo
1 parent 4700883 commit 5168e35

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

base/compiler/ssair/legacy.jl

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
5757
ci.linetable = ir.linetable
5858
ci.ssavaluetypes = ir.types
5959
ci.ssaflags = ir.flags
60+
for metanode in ir.meta
61+
push!(ci.code, metanode)
62+
push!(ci.codelocs, 1)
63+
push!(ci.ssavaluetypes, Any)
64+
push!(ci.ssaflags, 0x00)
65+
end
6066
# Translate BB Edges to statement edges
6167
# (and undo normalization for now)
6268
for i = 1:length(ci.code)

test/compiler/ssair.jl

+9
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ for compile in ("min", "yes")
8787
error("Interpreter test failed, cmd : $cmd")
8888
end
8989
end
90+
91+
# Issue #27104
92+
# Test whether meta nodes are still present after code optimization.
93+
let
94+
@noinline f(x, y) = x + y
95+
@test any(code_typed(f)[1][1].code) do ex
96+
Meta.isexpr(ex, :meta)
97+
end
98+
end

test/llvmpasses/noinline.jl

+21
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)