[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 01:14:35 PST 2020


psionic12 marked 4 inline comments as done.
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;
----------------
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.


================
Comment at: clang/test/Frontend/plugin-attribute.cpp:1
-// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -emit-llvm -S %s -o - 2>&1 | FileCheck %s --check-prefix=ATTRIBUTE
-// RUN: not %clang -fplugin=%llvmshlibdir/Attribute%pluginext -emit-llvm -DBAD_ATTRIBUTE -S %s -o - 2>&1 | FileCheck %s --check-prefix=BADATTRIBUTE
+// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -DGOOD_ATTR -fsyntax-only -Xclang -verify=goodattr %s
+// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -DBAD_ATTR -fsyntax-only -Xclang -verify=badattr %s
----------------
aaron.ballman wrote:
> I don't think we need a GOOD_ATTR and BAD_ATTR run line any longer. Instead, you can use a single RUN line with `-verify` (no `=`) and use `expected-error` and `expected-warning` on the lines that need the diagnostics. This means you can also get rid of the `@ line number` constructs and just write the expected comments on the source lines with diagnostics.
Seems the `GOOD_ATTR` and `BAD_ATTR` need to be exist since we use `-ast-dump` now, we need a clean build without error diagnostics to generate a nice AST.


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