[PATCH] D146342: [WIP][-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 22 11:28:49 PDT 2023


NoQ added a comment.

Yeah this information is probably at least partially unavailable in the fully parsed AST. We have all the instantiations with their AST copied from the original template AST, but we no longer remember *why* we copied it (which is what the `CodeSynthesisContext` stack captures) . And at this point there could actually be more than one reason (whereas the regular compiler warnings showed up the *first* time the instantiation was requested, so at that point there was just one reason *so far*).

I wonder if it's possible to build an "example" reason after the fact. There's probably no readily available solution but it might be possible to build one with relative ease 🤔 I'm not sure we need to do this for this patch.

But as a smaller subtask of this task, it's probably really valuable to at least make sure the current template arguments are explained. Eg., in

  template <typename T>
  T addFive(T t) {
    return t + 5;
  }
  
  void foo() {
    int *x = ...;
    x = addFive(x);
  }

it's very important to make sure that the warning about unsafe buffer operation `t + 5` carries a hint that `T` is `int *`. Without that the warning may be completely incomprehensible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146342



More information about the cfe-commits mailing list