./bin/opt: unknown pass name 'passname'

I have installed the llvm from this repository…
git clone --depth=1 GitHub - llvm/llvm-project: The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Note: the repository does not accept github pull requests at this moment. Please submit your patches at http://reviews.llvm.org.

I want to create a new pass that identifies all implicit invocations of constructors in a C++ program, including the source location, the variable involved and the constructor being invoked. hence I followed this link. Writing an LLVM Pass — LLVM 18.0.0git documentation

I have created a new directory with name : ConstructorPass in /llvm/lib/Transforms

Then I changed the /Transforms/CMakeLists.txt and added add_subdirectory(ConstructorPass)

Then I have created two files at ConstructorPass directory: CMakeLists.txt and ConstructorPass.cpp

Here is the CMakeLists.txt

add_llvm_library( LLVMConstructorPass MODULE

Here is the ConstructorPass.cpp
#include “llvm/Pass.h”
#include “llvm/IR/Function.h”
#include “llvm/IR/Module.h”
#include “llvm/IR/Instructions.h”
#include “llvm/Support/raw_ostream.h”

using namespace llvm;

namespace {
struct ConstructorPass : public FunctionPass {
static char ID;
ConstructorPass() : FunctionPass(ID) {}

    bool runOnFunction(Function &F) override {
        //functionality coded here...
        return modified;


char ConstructorPass::ID = 0;

static RegisterPass X(“constructor-pass”, “Identify implicit invocations of constructors in C++ functions”, false, false);

Then I tried to build the project using

llvm-project/build> cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G “Unix Makefiles” …/llvm

Then I have created a file hello.cpp at /llvm/build directory
Then I compiled the hello.cpp as

clang -c -emit-llvm hello.cpp

Then when I try to use the pass that I have created… I got this error…

./bin/opt -load lib/LLVMConstructorPass.so -passes=constructor-pass < hello.bc > /dev/null
./bin/opt: unknown pass name ‘constructor-pass’

This is the version:
llvm-project/build/bin$ llvm-cov --version
Ubuntu LLVM version 14.0.0

Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: alderlake

Please help me to fix this issue…

You’re trying to use the old pass manager, and not the new. Unfortunately it looks like the documentation you linked wasn’t updated. See this instead