Skip to content

Commit

Permalink
[ORC] Fix handling of casts in llvm.global_ctors.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lhames committed Apr 8, 2022
1 parent 1cee3d9 commit a76209c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions 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*)

@.str = private constant [12 x i8] c"constructor\00"
@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
}

0 comments on commit a76209c

Please sign in to comment.