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.
/// 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))
--- /dev/null
+; RUN: opt -passes=globalopt -S < %s | FileCheck %s
+
+; CHECK: @f1
+; CHECK: @f2
+
+@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
+}