[PATCH] D124553: [OpaquePtr][GlobalOpt] Don't attempt to evaluate global constructors with arguments
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 27 19:02:26 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e65291837aa: [OpaquePtr][GlobalOpt] Don't attempt to evaluate global constructors with… (authored by aeubanks).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124553/new/
https://reviews.llvm.org/D124553
Files:
llvm/lib/Transforms/Utils/CtorUtils.cpp
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Transforms/GlobalOpt/global-constructor-opaque-ptr.ll
Index: llvm/test/Transforms/GlobalOpt/global-constructor-opaque-ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GlobalOpt/global-constructor-opaque-ptr.ll
@@ -0,0 +1,14 @@
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
+; CHECK: @f1
+; CHECK: @f2
+
+ at llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @f1, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @f2, ptr null }]
+
+define void @f1(i32 %args) {
+ ret void
+}
+
+define i32 @f2(i32 %args) {
+ ret i32 0
+}
Index: llvm/lib/Transforms/Utils/Evaluator.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Evaluator.cpp
+++ llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -629,6 +629,8 @@
/// function.
bool Evaluator::EvaluateFunction(Function *F, Constant *&RetVal,
const SmallVectorImpl<Constant*> &ActualArgs) {
+ assert(ActualArgs.size() == F->arg_size() && "wrong number of arguments");
+
// Check to see if this function is already executing (recursion). If so,
// bail out. TODO: we might want to accept limited recursion.
if (is_contained(CallStack, F))
Index: llvm/lib/Transforms/Utils/CtorUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CtorUtils.cpp
+++ llvm/lib/Transforms/Utils/CtorUtils.cpp
@@ -98,8 +98,9 @@
if (isa<ConstantPointerNull>(CS->getOperand(1)))
continue;
- // Must have a function or null ptr.
- if (!isa<Function>(CS->getOperand(1)))
+ // Can only handle global constructors with no arguments.
+ Function *F = dyn_cast<Function>(CS->getOperand(1));
+ if (!F || F->arg_size() != 0)
return nullptr;
// Init priority must be standard.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124553.425680.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220428/e3fd4a36/attachment.bin>
More information about the llvm-commits
mailing list