[PATCH] D94640: adds more checks to -Wfree-nonheap-object

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 06:22:14 PST 2021


aaron.ballman added inline comments.


================
Comment at: clang/test/Analysis/free.c:84
+  // expected-warning at -1{{Argument to free() is a block, which is not memory allocated by malloc()}}
+  // expected-warning at -2{{attempt to call free on non-heap object : block expression}}
 }
----------------
cjdb wrote:
> aaron.ballman wrote:
> > cjdb wrote:
> > > aaron.ballman wrote:
> > > > The formatting for this diagnostic is somewhat unfortunate in that it has the leading space before the `:`. I think that changing the diagnostic to use a `%select` would be an improvement.
> > > I'm having a *lot* of difficulty getting `%select` to work. Here's what I've tried, but the space in `%select{ %2` is being ignored :(
> > > 
> > > ```
> > > : Warning<"attempt to call %0 on non-heap object%select{ %2|: block expression}1">,
> > > ```
> > We could cheat a little bit. :-D
> > 
> > `Warning<"attempt to call %0 on non-heap %select{object %2|object: block expression}1">`
> > 
> > (The diagnostic should probably be updated to distinguish between block expressions and lambda expressions, which may add another layer of `%select` not shown here.)
> That doesn't fix the issue, which is that everything before `%2` is deleted.
Huh? That seems very surprising given that we use this pattern in plenty of other places:

https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L483
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L685
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L1439

Can you post the output you're getting when you try my workaround? (I don't know if your original attempt will work because of the lack of whitespace before the `%select` in `object%select`.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94640



More information about the cfe-commits mailing list