samasri / omr

Eclipse OMR™ Cross platform components for building reliable, high performance language runtimes
http://www.eclipse.org/omr
Other
0 stars 2 forks source link

Classes visited when processing call functions are different than the ones visited in VisitCXXRecord #44

Open samasri opened 6 years ago

samasri commented 6 years ago

How the Function Table is Populated

The Function table is filled from information obtained from VisitCXXRecord. In VisitCXXRecord, classes are filtered by the following if statements before being processed by recordParents(std::string, std::string) (signature is specified since there are two recordParents functions):

if(!decl || !decl->isClass() || !decl->hasDefinition()) return true;
if(HMConsumer::shouldIgnoreClassName(decl)) continue;

The way class declarations are being retrieved is by either one of the two ways:

  1. VisitCXXRecord function is being called by RecursiveASTVisitor and hence the decl is provided from that class.
  2. We traverse the bases of a declaration provided by the VisitCXXRecord which we can get in the form of QualType. Try to convert them to CXXRecordDecl. If the last was successful (not null), it means this points to a parent class decl. This method excludes some (but not all) template classes (as described in #18). At this stage, the function declarations are coming from the AST. Hence, in case of template classes, the signature of functions depending on generic types still have generic parameters.

How the FunctionCall Table is Populated

When processing call functions (in processCallExpressions function), the class declaration is coming from the CXXMemberCallExpr which processes all templates. At this stage, generic types of templates are already resolved. Hence, signatures of functions depending on the generic classes will have concrete class types since the receiver is an instance of a template with its generic types already resolved.

The problem

Consider the following hypothetical function:

template <class T> void setValue(T value);
setValue<int>(5);

In the Function table, we will have the signature of that function as follows: void setValue(T). However, in the FunctionCall table, we will have the signature as follows: void setValue(int) Hence, the same function will have different signatures in FuncationCalls based how it is instantiated. Therefore, there are functions in FunctionCall that cannot be linked to FunctionIDs in Function since it is not possible to match their signatures with the Function table data.