Error: ‘class llvm::PassManager<llvm::Module>’ has no member named ‘add’

Hi, I am begineer to llvm, implementing a main.cpp from

A) : When I am declaring a command:
PassManager PM
PM.add(new DataLayout td)

It shows error:

error: missing template arguments before ‘PM’

PassManager PM;

main_test.cpp:48:2: error: ‘PM’ was not declared in this scope
PM.add(new DataLayout(td));

Keeping in mind the above error, I changed the code as:PassManager PM
PM.add(new DataLayout td)

I dont know, whether the above change is the correct one or not. But the error is changed to:

error: ‘class llvm::PassManagerllvm::Module’ has no member named ‘add’
PM.add(new DataLayout(td));

Here is mine source code:

Hi Ratnesh,

the PassManager used in that example has moved into the legacy namespace:


Hi Philip,
I also tried that including file:
#include “llvm/IR/LegacyPassManager.h”
but error remain same. Please help.

Hi Ratnesh,

Did you change your variable declaration to "legacy::PassManager PM;"
after adding the include for the legacy pass manager?

Best regards

Yes, I did that. Now the error is comming:

error: no matching function for call to ‘llvm::legacy::PassManager::add(llvm::DataLayout*)’
PM.add(new DataLayout(td));
In file included from main_test.cpp:15:0:
/tmp/llvm/include/llvm/IR/LegacyPassManager.h:55:8: note: candidate: virtual void llvm::legacy::PassManager::add(llvm::Pass*)
void add(Pass P) override;
/tmp/llvm/include/llvm/IR/LegacyPassManager.h:55:8: note: no known conversion for argument 1 from ‘llvm::DataLayout
’ to ‘llvm::Pass*’