================
@@ -4133,6 +4217,44 @@ void 
PragmaMaxTokensTotalHandler::HandlePragma(Preprocessor &PP,
   PP.overrideMaxTokens(MaxTokens, Loc);
 }
 
+static void zOSPragmaHandlerHelper(Preprocessor &PP, Token &Tok,
+                                   tok::TokenKind TokKind) {
+  Token AnnotTok;
+  AnnotTok.startToken();
+  AnnotTok.setKind(TokKind);
+  AnnotTok.setLocation(Tok.getLocation());
+  AnnotTok.setAnnotationEndLoc(Tok.getLocation());
+  SmallVector<Token, 8> TokenVector;
+  // Suck up all of the tokens before the eod.
+  for (; Tok.isNot(tok::eod); PP.Lex(Tok)) {
+    TokenVector.push_back(Tok);
+    AnnotTok.setAnnotationEndLoc(Tok.getLocation());
+  }
+  // Add a sentinel EoF token to the end of the list.
+  Token EoF;
+  EoF.startToken();
+  EoF.setKind(tok::eof);
+  EoF.setLocation(Tok.getLocation());
+  TokenVector.push_back(EoF);
+  // We must allocate this array with new because EnterTokenStream is going to
+  // delete it later.
+  markAsReinjectedForRelexing(TokenVector);
+  auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
----------------
mikaelholmen wrote:

Hello @perry-ca 

If I build clang with ASAN and run e.g. the new pragma-export-failing.cpp 
testcase, I get a
```
==539280==ERROR: LeakSanitizer: detected memory leaks
```
complaint pointing back to this line:
```
Direct leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0x55f29681aded in operator new[](unsigned long)
    #1 0x55f2a351b7cb in make_unique<clang::Token[], 0>
    #2 0x55f2a351b7cb in zOSPragmaHandlerHelper 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParsePragma.cpp:4242:21
    #3 0x55f2a351b7cb in (anonymous 
namespace)::PragmaExportHandler::HandlePragma(clang::Preprocessor&, 
clang::PragmaIntroducer, clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParsePragma.cpp:4255:3
    #4 0x55f2a6be10a8 in 
clang::PragmaNamespace::HandlePragma(clang::Preprocessor&, 
clang::PragmaIntroducer, clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Pragma.cpp:120:12
    #5 0x55f2a6be155c in 
clang::Preprocessor::HandlePragmaDirective(clang::PragmaIntroducer) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Pragma.cpp:174:19
    #6 0x55f2a6b7fdd8 in clang::Preprocessor::HandleDirective(clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/PPDirectives.cpp:1458:14
    #7 0x55f2a6aefbe2 in clang::Lexer::LexTokenInternal(clang::Token&, bool) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Lexer.cpp:4539:7
    #8 0x55f2a6ae7870 in clang::Lexer::Lex(clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Lexer.cpp:3739:24
    #9 0x55f2a6c12edb in clang::Preprocessor::Lex(clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Preprocessor.cpp:905:11
    #10 0x55f2a6b68caa in clang::Preprocessor::CachingLex(clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/PPCaching.cpp:91:3
    #11 0x55f2a6b693d8 in 
clang::Preprocessor::CLK_CachingLexer(clang::Preprocessor&, clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/include/clang/Lex/Preprocessor.h:3199:7
    #12 0x55f2a6c12edb in clang::Preprocessor::Lex(clang::Token&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Lex/Preprocessor.cpp:905:11
    #13 0x55f2a34b69c7 in clang::Parser::ConsumeBrace() 
/repo/llvm-project/llvm/build-all-asan/../../clang/include/clang/Parse/Parser.h:670:8
    #14 0x55f2a359d4c0 in consumeOpen 
/repo/llvm-project/llvm/build-all-asan/../../clang/include/clang/Parse/RAIIObjectsForParser.h:471:17
    #15 0x55f2a359d4c0 in 
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, 
clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseDeclCXX.cpp:3648:5
    #16 0x55f2a3596958 in 
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, 
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, 
clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, 
clang::ParsedAttributes&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseDeclCXX.cpp:2170:7
    #17 0x55f2a35f22d8 in 
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, 
clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, 
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, 
clang::ImplicitTypenameContext) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseDecl.cpp:4465:7
    #18 0x55f2a36732fb in ParseDeclarationSpecifiers 
/repo/llvm-project/llvm/build-all-asan/../../clang/include/clang/Parse/Parser.h:1843:12
    #19 0x55f2a36732fb in 
clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, 
clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, 
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseTemplate.cpp:201:3
    #20 0x55f2a3670f13 in 
clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext,
 clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseTemplate.cpp:147:10
    #21 0x55f2a366fa31 in 
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, 
clang::SourceLocation&, clang::ParsedAttributes&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseTemplate.cpp:43:10
    #22 0x55f2a35e3282 in 
clang::Parser::ParseDeclaration(clang::DeclaratorContext, 
clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, 
clang::SourceLocation*) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseDecl.cpp:1889:12
    #23 0x55f2a34c743a in 
clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, 
clang::ParsedAttributes&, clang::ParsingDeclSpec*) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/Parser.cpp:912:14
    #24 0x55f2a34c3871 in 
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, 
clang::Sema::ModuleImportState&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/Parser.cpp:706:12
    #25 0x55f2a349eecd in clang::ParseAST(clang::Sema&, bool, bool) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Parse/ParseAST.cpp:170:20
    #26 0x55f29fe2b633 in clang::FrontendAction::Execute() 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Frontend/FrontendAction.cpp:1313:3
    #27 0x55f29fcf9e38 in 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/Frontend/CompilerInstance.cpp:1007:33
    #28 0x55f2a00b90d7 in 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
/repo/llvm-project/llvm/build-all-asan/../../clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:310:25
    #29 0x55f296827ef5 in cc1_main(llvm::ArrayRef<char const*>, char const*, 
void*) 
/repo/llvm-project/llvm/build-all-asan/../../clang/tools/driver/cc1_main.cpp:304:15
    #30 0x55f29682027b in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, 
llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) 
/repo/llvm-project/llvm/build-all-asan/../../clang/tools/driver/driver.cpp:226:12
    #31 0x55f29681e5e2 in clang_main(int, char**, llvm::ToolContext const&) 
/repo/llvm-project/llvm/build-all-asan/../../clang/tools/driver/driver.cpp:274:12
    #32 0x55f2968404ea in main 
/repo/llvm-project/llvm/build-all-asan/tools/clang/tools/driver/clang-driver.cpp:17:10
    #33 0x7f48946607e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) 
(BuildId: 8fcf28d58291e94e5ad7d614fd6d41ec26ab43bb)

SUMMARY: AddressSanitizer: 120 byte(s) leaked in 1 allocation(s).
```
Does that make sense?

https://github.com/llvm/llvm-project/pull/141671
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to