@@ -146,10 +146,12 @@ LLVMTypeHierarchy::removeStructOrClassPrefix(const llvm::StructType &T) {
146146std::string
147147LLVMTypeHierarchy::removeStructOrClassPrefix (llvm::StringRef TypeName) {
148148 if (TypeName.startswith (StructPrefix)) {
149- return TypeName.drop_front (StructPrefix.size ()).str ();
149+ TypeName = TypeName.drop_front (StructPrefix.size ());
150+ } else if (TypeName.startswith (ClassPrefix)) {
151+ TypeName = TypeName.drop_front (ClassPrefix.size ());
150152 }
151- if (TypeName.startswith (ClassPrefix )) {
152- return TypeName.drop_front (ClassPrefix. size ()). str ( );
153+ if (TypeName.endswith ( " .base " )) {
154+ TypeName = TypeName.drop_back ( llvm::StringRef ( " .base " ). size () );
153155 }
154156 return TypeName.str ();
155157}
@@ -231,18 +233,15 @@ LLVMTypeHierarchy::getSubTypes(const llvm::Module & /*M*/,
231233 if (const auto *I =
232234 llvm::dyn_cast<llvm::ConstantStruct>(TI->getInitializer ())) {
233235 for (const auto &Op : I->operands ()) {
234- if (auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(Op)) {
235- if (auto *BC = llvm::dyn_cast<llvm::BitCastOperator>(CE)) {
236- if (BC->getOperand (0 )->hasName ()) {
237- auto Name = BC->getOperand (0 )->getName ();
238- if (Name.find (TypeInfoPrefix) != llvm::StringRef::npos) {
239- auto ClearName =
240- removeTypeInfoPrefix (llvm::demangle (Name.str ()));
241- if (auto TypeIt = ClearNameTypeMap.find (ClearName);
242- TypeIt != ClearNameTypeMap.end ()) {
243- SubTypes.push_back (TypeIt->second );
244- }
245- }
236+ const auto *CE = Op->stripPointerCastsAndAliases ();
237+
238+ if (CE->hasName ()) {
239+ auto Name = CE->getName ();
240+ if (Name.find (TypeInfoPrefix) != llvm::StringRef::npos) {
241+ auto ClearName = removeTypeInfoPrefix (llvm::demangle (Name.str ()));
242+ if (auto TypeIt = ClearNameTypeMap.find (ClearName);
243+ TypeIt != ClearNameTypeMap.end ()) {
244+ SubTypes.push_back (TypeIt->second );
246245 }
247246 }
248247 }
@@ -329,8 +328,9 @@ LLVMTypeHierarchy::getSubTypes(const llvm::StructType *Type) const {
329328 return {};
330329}
331330
332- const llvm::StructType *
333- LLVMTypeHierarchy::getType (llvm::StringRef TypeName) const {
331+ template <typename GraphT>
332+ static const llvm::StructType *getTypeImpl (const GraphT &TypeGraph,
333+ llvm::StringRef TypeName) {
334334 for (auto V : boost::make_iterator_range (boost::vertices (TypeGraph))) {
335335 if (TypeGraph[V].Type ->getName () == TypeName) {
336336 return TypeGraph[V].Type ;
@@ -339,6 +339,17 @@ LLVMTypeHierarchy::getType(llvm::StringRef TypeName) const {
339339 return nullptr ;
340340}
341341
342+ const llvm::StructType *
343+ LLVMTypeHierarchy::getType (llvm::StringRef TypeName) const {
344+ if (const auto *Ty = getTypeImpl (TypeGraph, TypeName)) {
345+ return Ty;
346+ }
347+
348+ // Sometimes, clang adds a .base suffix
349+ std::string TN = TypeName.str () + " .base" ;
350+ return getTypeImpl (TypeGraph, TypeName);
351+ }
352+
342353std::vector<const llvm::StructType *> LLVMTypeHierarchy::getAllTypes () const {
343354 std::vector<const llvm::StructType *> Types;
344355 Types.reserve (boost::num_vertices (TypeGraph));
0 commit comments