-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][frontend] Support applying the annotate attribute to statements #111841
Changes from 2 commits
6ca0de7
88e7bf7
3864b0e
ae06e53
be28c2b
c09ac95
6fd9661
753b168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1537,6 +1537,7 @@ namespace { | |
NamedDecl *FirstQualifierInScope = nullptr, | ||
bool AllowInjectedClassName = false); | ||
|
||
const AnnotateAttr *TransformAnnotateAttr(const AnnotateAttr *AA); | ||
const CXXAssumeAttr *TransformCXXAssumeAttr(const CXXAssumeAttr *AA); | ||
const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | ||
const NoInlineAttr *TransformStmtNoInlineAttr(const Stmt *OrigS, | ||
|
@@ -2125,6 +2126,19 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | |
Arg, PackIndex); | ||
} | ||
|
||
const AnnotateAttr * | ||
TemplateInstantiator::TransformAnnotateAttr(const AnnotateAttr *AA) { | ||
SmallVector<Expr *> Args; | ||
for (Expr *Arg : AA->args()) { | ||
ExprResult Res = getDerived().TransformExpr(Arg); | ||
if (!Res.isUsable()) | ||
return AA; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I see this elsewhere, and I'm not thrilled that this is our behavior (returning the uninstantiated version of the attribute). For Annotate, I wonder if instead we should just continue and NOT add this argument (so if you have one that fails all its args, we continue, but you get an annotate with no args, if 1/2 transform, you get 1/2)? WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that I like this approach. I agree that silent failure is bad, but silently dropping some arguments seems potentially as bad or worse. I'd rather we produce an error... but if so, I think that might be worth doing separately as part of a cleanup that does so across the board (not just for Annotate). WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We won't be silently dropping them though, |
||
Args.push_back(Res.get()); | ||
} | ||
return AnnotateAttr::CreateImplicit(getSema().Context, AA->getAnnotation(), | ||
Args.data(), Args.size(), AA->getRange()); | ||
} | ||
|
||
const CXXAssumeAttr * | ||
TemplateInstantiator::TransformCXXAssumeAttr(const CXXAssumeAttr *AA) { | ||
ExprResult Res = getDerived().TransformExpr(AA->getAssumption()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically identical to what we do for non-statements, right? We should probably extract this to a 'Check' function that SemaDeclAttr and SemaStmtAttr boht can use.