[PATCH] D91979: [Clang][Attr] Introduce the `assume` function attribute

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 8 10:31:37 PST 2020


aaron.ballman added a comment.

Thank you for your patience with the delays getting to your review! Along with the documentation question, one line of thinking I'm also not clear on is whether this should be a type-based attribute rather than a declaration-based attribute. For instance, if you want to write an assumption about the parameters to a function, those are not in scope for a declaration attribute but are for a type attribute. But also, it seems like this assumption information is something that would be useful to carry around as part of the function's identity. For instance, would users want to be able to make a call through a function pointer and have the same set of assumptions conveyed to the backend?



================
Comment at: clang/include/clang/Basic/AttrDocs.td:3931
+expression that can be assumed to be non-zero, the assumption is expressed as
+a string and it holds for the entire function.
+
----------------
It's not clear to me how this string literal relates to program constructs being assumed. I think adding some example usage would be very instructive, but I also think the string literal needs more documentation. e.g.,
```
__attribute__((assume("the parameter 'i' will be nonnegative"))) void func(int i);
```
seems reasonable from the existing text but probably isn't what we're looking for. ;-)

If we're going to require the assumption to be a valid expression, then I'm not certain a string literal is doing us any favors given that there won't be any expression validity checking done on the string. Why not support an expression as the argument directly?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91979/new/

https://reviews.llvm.org/D91979



More information about the cfe-commits mailing list