mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 18:06:32 +00:00

In -fdelayed-template-parsing mode, templates that aren't used are not parsed at all. For some diagnostic plugins, this is a problem since they want to analyse the contents of the template function body. What has been suggested on cfe-dev [1] is to explicitly parse interesting templates in HandleTranslationUnit(); IWYU does this for example [2]. This is workable, but since the delayed parsing doesn't run below a call to ParseTopLevelDecl(), no DestroyTemplateIdAnnotationsRAIIObj object is on the stack to clean up TemplateIds that are created during parsing. To fix this, let ~Parser() clean them up in delayed template parsing mode instead of leaking (or asserting in +Assert builds). (r219810, relanded in r220400, fixed the same problem in incremental processing mode; the review thread of r219810 has a good discussion of the problem.) To test this, give the PrintFunctionNames plugin a flag to force parsing of a template and add a test that uses it in -fdelayed-template-parsing mode. Without the Parser.cpp change, that test asserts. 1: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-August/038415.html 2: https://code.google.com/p/include-what-you-use/source/detail?r=566 llvm-svn: 237531
18 lines
685 B
C++
18 lines
685 B
C++
// RUN: %clang_cc1 -fdelayed-template-parsing -load %llvmshlibdir/PrintFunctionNames%pluginext -plugin print-fns -plugin-arg-print-fns -parse-template -plugin-arg-print-fns ForcedTemplate %s 2>&1 | FileCheck %s
|
|
// REQUIRES: plugins, examples
|
|
|
|
template <typename T>
|
|
void TemplateDep();
|
|
|
|
// CHECK: top-level-decl: "ForcedTemplate"
|
|
// The plugin should force parsing of this template, even though it's
|
|
// not used and -fdelayed-template-parsing is specified.
|
|
// CHECK: warning: expression result unused
|
|
// CHECK: late-parsed-decl: "ForcedTemplate"
|
|
template <typename T>
|
|
void ForcedTemplate() {
|
|
TemplateDep<T>(); // Shouldn't crash.
|
|
|
|
""; // Triggers the warning checked for above.
|
|
}
|