[cfe-dev] Newbie Related Dependency Questions
Andrew Gozillon via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 26 19:08:04 PST 2016
Hi Erik,
Thanks very much for the quick reply and the great answer! I will try elaborate on my first question a little bit to try and clear it up (I apologise if it doesn't, I'm not great for explanations).
Within SemaType.cpp some of the type attributes take in integer parameters, however they can not be dependent or value dependent (for example by a template'd const int) as shown by the below snippet from the HandleVectorSizeAttr function which will emit an error if its tried:
Expr<http://clang.llvm.org/doxygen/classclang_1_1Expr.html> *sizeExpr = static_cast<Expr<http://clang.llvm.org/doxygen/classclang_1_1Expr.html> *>(Attr.getArgAsExpr<http://clang.llvm.org/doxygen/classclang_1_1AttributeList.html#a265d2e7800361a5124d7455fdd432424>(0));
llvm::APSInt vecSize(32);
if (sizeExpr->isTypeDependent<http://clang.llvm.org/doxygen/classclang_1_1Expr.html#a48cd7038510f42d44e314d1b8d294824>() || sizeExpr->isValueDependent<http://clang.llvm.org/doxygen/classclang_1_1Expr.html#a34f1652a9072dfd3c7119d23e1a14fa5>() || !sizeExpr->isIntegerConstantExpr<http://clang.llvm.org/doxygen/classclang_1_1Expr.html#a664cbf5948aae551f2080170628ea5ac>(vecSize, S.Context<http://clang.llvm.org/doxygen/classclang_1_1Sema.html#a3ccddacb1f4f71b084296175cc9e5b0e>)) { S.Diag<http://clang.llvm.org/doxygen/classclang_1_1Sema.html#ad29dfd1f2677772bf6b1da186a7583c3>(Attr.getLoc<http://clang.llvm.org/doxygen/classclang_1_1AttributeList.html#a764e55754a52aa43b991dbbb24fa1450>(), diag::err_attribute_argument_type)<< Attr.getName<http://clang.llvm.org/doxygen/classclang_1_1AttributeList.html#ad33e72a3989e9a61697da22d0211bf15>() << AANT_ArgumentIntegerConstant<http://clang.llvm.org/doxygen/namespaceclang.html#a702b0ec61c5bb9df98d3364a170c0dfca026f679d45ce5b7f618b89ac18d8595e> << sizeExpr->getSourceRange<http://clang.llvm.org/doxygen/classclang_1_1Stmt.html#a6844392ee6148b5fe821f211b95e5d1b>(); Attr.setInvalid<http://clang.llvm.org/doxygen/classclang_1_1AttributeList.html#ad2ce5246eed483669e582893448602d8>();
return;
}
So for example code like the below would not be use-able:
template <const int n>
void foo()
{
int *__attribute__((aligned(n))) test;
}
I was wondering if it's possible to try and do an early instantiation of the n parameter (sizeExpr in the context of the SemaType.cpp function) within the HandleXXXAttr function (or delay parsing until it can similar to the DeclAttr's in SemaDeclAttr) and get the value out of it rather than emit a diagnostic error. I imagine it isn't possible, but I thought I'd ask just in-case!
Best Regards,
Andrew
________________________________
From: Erik Pilkington <erik.pilkington at gmail.com>
Sent: 24 December 2016 03:26:24
To: Andrew Gozillon
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Newbie Related Dependency Questions
On Dec 23, 2016, at 8:02 PM, Andrew Gozillon via cfe-dev <cfe-dev at lists.llvm.org<mailto: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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161227/ebee0a75/attachment.html>
More information about the cfe-dev
mailing list