Skip to content

Commit e451d55

Browse files
committed
[ORC] Fix sorting of contructors by priority
The code was incorrectly sorting by the function address. Differential Revision: https://reviews.llvm.org/D123311
1 parent 85285be commit e451d55

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
524524
llvm::sort(InitsOrDeInits,
525525
[](const std::pair<Function *, unsigned> &LHS,
526526
const std::pair<Function *, unsigned> &RHS) {
527-
return LHS.first < RHS.first;
527+
return LHS.second < RHS.second;
528528
});
529529

530530
auto *InitOrDeInitFuncEntryBlock =

llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout \
99
; RUN: -jd extra -extra-module %s -jd main %S/Inputs/noop-main.ll | FileCheck %s
1010
;
11+
; CHECK: Hello from constructor
1112
; CHECK: Hello
1213
; CHECK: [ {{.*}}main{{.*}} ]
1314
; CHECK: Goodbye
@@ -17,11 +18,12 @@
1718

1819
@f = global %class.Foo zeroinitializer, align 1
1920
@__dso_handle = external global i8
20-
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_hello.cpp, i8* null }]
21+
@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_hello.cpp, i8* null }, { i32, void ()*, i8* } { i32 1024, void ()* @constructor, i8* null }]
2122
@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @printf_wrapper, i8* null }]
2223
@str = private unnamed_addr constant [6 x i8] c"Hello\00"
2324
@str2 = private unnamed_addr constant [8 x i8] c"Goodbye\00"
2425
@str3 = global [14 x i8] c"Goodbye again\00"
26+
@str4 = private unnamed_addr constant [23 x i8] c"Hello from constructor\00"
2527

2628
define linkonce_odr void @_ZN3FooD1Ev(%class.Foo* nocapture readnone %this) unnamed_addr align 2 {
2729
entry:
@@ -45,3 +47,9 @@ entry:
4547
}
4648

4749
declare i32 @puts(i8* nocapture readonly)
50+
51+
define void @constructor() {
52+
entry:
53+
%0 = tail call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str4, i64 0, i64 0))
54+
ret void
55+
}

0 commit comments

Comments
 (0)