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

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 11:20:18 PST 2021


cjdb marked 3 inline comments as done.
cjdb 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}}
 }
----------------
aaron.ballman wrote:
> 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`.)
Yeah, not sure what was going on here (maybe I didn't hit save before testing?), since it ICEd up when I re-applied it. Anyway, got it working :-)


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