[cfe-dev] Newbie Related Dependency Questions

Erik Pilkington via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 23 19:26:24 PST 2016


> On Dec 23, 2016, at 8:02 PM, Andrew Gozillon via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi,
> 
> I'm pretty new to working/tinkering with the Clang compiler, so I'm sorry ahead of time if these questions aren't relevant to this mailing list or seem silly. 

Welcome! No need to apologize :)

> My first question is mainly, is it at all possible to instantiate a non-type template based Expr during the type formation stage and if so would it be possible to get pointed in the right direction to do it? (for example inside one of the Attributes that intake an integer parameter). Or is it impossible/incorrect to rely on a dependent parameter at this stage (I have noticed most things throw a diagnostic error if the value is dependent or type dependent)? 

I’m not sure what your asking here. Maybe you could provide some example code?

> My other possibly more difficult to answer question is how (or where in the source code if that's even possible) is dependency passed upwards to parent statements/expressions (types in general)? For example if I have a std::same_as with a parameter that is dependent the std::same_as will also by extension be dependent until its child is no longer dependent. 

There is a bit in every Type that represents if it is dependent. For example, in:

template <class Type> void f() {
  Type D;
  std::same_as(D, 42);
}

During Sema of the CallExpr (Sema::ActOnCallExpr) to std::same_as, we check if any of the argument types are dependent, and if so we leave the type of the call as dependent, to be resolved during instantiation (This is done in SemaExpr.cpp:5196). This bit is set for the type of the subexpression D, and for the type of the call expression, but not for the type of the subexpression 42. Semantic analysis works bottom up from the perspective of the AST, so we’ve ActOn’d both D and 42 by the time we ActOn the CallExpr, meaning we can propagate dependent types up the AST as it is being constructed. Hope that answers your question.

> Again sorry if these questions are out of context for this mailing list and thank you very much for your time.
> 
> Best Regards,
> Andrew
> 
> 
> 
> Please consider the environment and think before you print. 
> 
> The University of the West of Scotland is a registered Scottish charity. Charity number SC002520. 
> 
> This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. 
> 
> Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the University of the West of Scotland. 
> 
> As a public body, the University of the West of Scotland may be required to make available emails as well as other written forms of information as a result of a request made under the Freedom of Information (Scotland) Act 2002. _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161223/15b284af/attachment.html>


More information about the cfe-dev mailing list