[llvm] a76209c - [ORC] Fix handling of casts in llvm.global_ctors.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 17:06:45 PDT 2022
Author: Lang Hames
Date: 2022-04-07T17:06:38-07:00
New Revision: a76209c265bdaca09d46ca4744c2d6e3602c908a
URL: https://github.com/llvm/llvm-project/commit/a76209c265bdaca09d46ca4744c2d6e3602c908a
DIFF: https://github.com/llvm/llvm-project/commit/a76209c265bdaca09d46ca4744c2d6e3602c908a.diff
LOG: [ORC] Fix handling of casts in llvm.global_ctors.
Removes a bogus dyn_cast_or_null that was breaking cast-expression handling when
parsing llvm.global_ctors.
The intent of this code was to identify Functions nested within cast
expressions, but the offending dyn_cast_or_null was actually blocking that:
Since a function is not a cast expression, we would set FuncC to null and break
the loop without finding the Function. The cast was not necessary either:
Functions are already Constants, and we didn't need to do anything
ConstantExpr-specific with FuncC, so we could just drop the cast.
Thanks to Jonas Hahnfeld for tracking this down.
http://llvm.org/PR54797
Added:
llvm/test/ExecutionEngine/Orc/global-ctor-with-cast.ll
Modified:
llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
index ae2d47fb8c5eb..cbc27980f57a3 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
@@ -62,7 +62,7 @@ CtorDtorIterator::Element CtorDtorIterator::operator*() const {
break;
} else if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
if (CE->isCast())
- FuncC = dyn_cast_or_null<ConstantExpr>(CE->getOperand(0));
+ FuncC = CE->getOperand(0);
else
break;
} else {
diff --git a/llvm/test/ExecutionEngine/Orc/global-ctor-with-cast.ll b/llvm/test/ExecutionEngine/Orc/global-ctor-with-cast.ll
new file mode 100644
index 0000000000000..d8ef219c025f3
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/global-ctor-with-cast.ll
@@ -0,0 +1,19 @@
+; Test that global constructors behind casts are run
+;
+; RUN: lli -jit-kind=orc %s | FileCheck %s
+;
+; CHECK: constructor
+
+declare i32 @puts(i8*)
+
+ at .str = private constant [12 x i8] c"constructor\00"
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* bitcast (i32 ()* @constructor to void ()*), i8* null }]
+
+define internal i32 @constructor() #0 {
+ %call = tail call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
+ ret i32 0
+}
+
+define i32 @main() {
+ ret i32 0
+}
More information about the llvm-commits
mailing list