[llvm] e451d55 - [ORC] Fix sorting of contructors by priority

Jonas Hahnfeld via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 00:14:42 PDT 2022


Author: Jonas Hahnfeld
Date: 2022-05-11T09:06:41+02:00
New Revision: e451d552348bc714614d294e32dfbe7ec2cd4005

URL: https://github.com/llvm/llvm-project/commit/e451d552348bc714614d294e32dfbe7ec2cd4005
DIFF: https://github.com/llvm/llvm-project/commit/e451d552348bc714614d294e32dfbe7ec2cd4005.diff

LOG: [ORC] Fix sorting of contructors by priority

The code was incorrectly sorting by the function address.

Differential Revision: https://reviews.llvm.org/D123311

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
    llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 7a490ebaa09e6..26d221100b984 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -524,7 +524,7 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
       llvm::sort(InitsOrDeInits,
                  [](const std::pair<Function *, unsigned> &LHS,
                     const std::pair<Function *, unsigned> &RHS) {
-                   return LHS.first < RHS.first;
+                   return LHS.second < RHS.second;
                  });
 
       auto *InitOrDeInitFuncEntryBlock =

diff  --git a/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll b/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
index 3b1cf7f9ed63b..961f9aab3b6dc 100644
--- a/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
+++ b/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
@@ -8,6 +8,7 @@
 ; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout \
 ; RUN:   -jd extra -extra-module %s -jd main %S/Inputs/noop-main.ll | FileCheck %s
 ;
+; CHECK: Hello from constructor
 ; CHECK: Hello
 ; CHECK: [ {{.*}}main{{.*}} ]
 ; CHECK: Goodbye
@@ -17,11 +18,12 @@
 
 @f = global %class.Foo zeroinitializer, align 1
 @__dso_handle = external global i8
- at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_hello.cpp, i8* null }] 
+ at 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 }]
 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @printf_wrapper, i8* null }]
 @str = private unnamed_addr constant [6 x i8] c"Hello\00"
 @str2 = private unnamed_addr constant [8 x i8] c"Goodbye\00"
 @str3 = global [14 x i8] c"Goodbye again\00"
+ at str4 = private unnamed_addr constant [23 x i8] c"Hello from constructor\00"
 
 define linkonce_odr void @_ZN3FooD1Ev(%class.Foo* nocapture readnone %this) unnamed_addr align 2 {
 entry:
@@ -45,3 +47,9 @@ entry:
 }
 
 declare i32 @puts(i8* nocapture readonly)
+
+define void @constructor() {
+entry:
+  %0 = tail call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str4, i64 0, i64 0))
+  ret void
+}


        


More information about the llvm-commits mailing list