commit | b87834ae6b5b47b9881b5e8eddaeaeb57e16b891 | [log] [tgz] |
---|---|---|
author | Younan Zhang <zyn7109@gmail.com> | Tue Apr 23 20:34:22 2024 +0800 |
committer | Copybara-Service <copybara-worker@google.com> | Tue Apr 23 05:40:07 2024 -0700 |
tree | 13f71ef84b6beb5a9aa6d6759bdc31982e2c1968 | |
parent | fbf3c3d4174cb7d3f4b70c66afc6994cfc4c53c2 [diff] |
[Clang][Parser] Don't always destroy template annotations at the end of a declaration (#89494) Since [6163aa9](https://github.com/llvm/llvm-project/commit/6163aa96799cbad7f2f58e02c5bebee9647056a5#diff-3a7ef0bff7d2b73b4100de636f09ea68b72eda191b39c8091a6a1765d917c1a2), we have introduced an optimization that almost always destroys TemplateIdAnnotations at the end of a function declaration. This doesn't always work properly: a lambda within a default template argument could also result in such deallocation and hence a use-after-free bug while building a type constraint on the template parameter. This patch adds another flag to the parser to tell apart cases when we shouldn't do such cleanups eagerly. A bit complicated as it is, this retains the optimization on a highly templated function with lots of generic lambdas. Note the test doesn't always trigger a conspicuous bug/crash even with a debug build. But a sanitizer build can detect them, I believe. Fixes https://github.com/llvm/llvm-project/issues/67235 Fixes https://github.com/llvm/llvm-project/issues/89127 GitOrigin-RevId: 8ab3caf4d3acef29f373e09bc6a0ac459918930e