[PATCH] D92006: Refactoring the attrubute plugin example to fit the new API
Yafei Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 7 03:10:47 PST 2020
psionic12 added inline comments.
================
Comment at: clang/examples/Attribute/Attribute.cpp:81
+ D->addAttr(AnnotateAttr::Create(S.Context, "example", &Arg0,
+ Attr.getNumArgs(), Attr.getRange()));
return AttributeApplied;
----------------
psionic12 wrote:
> aaron.ballman wrote:
> > This looks dangerous to me -- if there are two or three arguments supplied, then this code will result in a buffer overrun.
> Oh, didn't noticed that, but I checked the code it's hard to get the address of the argument buffer, all APIs about it is private, even if `ArgsUnion const *getArgsBuffer() const`, which I think is not very reasonable. Do you think I should copy all the arguments to a new buffer (not very effective), or do you think I should contribute a patch to make the API public?
>
> There's a third way, `getTrailingObjects()` is public in TrailingObjects, it is possible to cast an `ParsedAttr` to a `TrailingObjects`, but I think it's too hacky.
I take times trying and found out it's more difficult to use the original buffer, so I use a vector to collect the arguments instead.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92006/new/
https://reviews.llvm.org/D92006
More information about the cfe-commits
mailing list