Bug Summary

File:tools/clang/lib/Frontend/ASTMerge.cpp
Warning:line 41, column 55
Potential leak of memory pointed to by field 'Obj'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ASTMerge.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/lib/Frontend -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Frontend -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/lib/Frontend -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Frontend/ASTMerge.cpp
1//===-- ASTMerge.cpp - AST Merging Frontend Action --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include "clang/Frontend/ASTUnit.h"
10#include "clang/AST/ASTContext.h"
11#include "clang/AST/ASTDiagnostic.h"
12#include "clang/AST/ASTImporter.h"
13#include "clang/Basic/Diagnostic.h"
14#include "clang/Frontend/CompilerInstance.h"
15#include "clang/Frontend/FrontendActions.h"
16
17using namespace clang;
18
19std::unique_ptr<ASTConsumer>
20ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
21 return AdaptedAction->CreateASTConsumer(CI, InFile);
22}
23
24bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI) {
25 // FIXME: This is a hack. We need a better way to communicate the
26 // AST file, compiler instance, and file name than member variables
27 // of FrontendAction.
28 AdaptedAction->setCurrentInput(getCurrentInput(), takeCurrentASTUnit());
29 AdaptedAction->setCompilerInstance(&CI);
30 return AdaptedAction->BeginSourceFileAction(CI);
31}
32
33void ASTMergeAction::ExecuteAction() {
34 CompilerInstance &CI = getCompilerInstance();
35 CI.getDiagnostics().getClient()->BeginSourceFile(
36 CI.getASTContext().getLangOpts());
37 CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
38 &CI.getASTContext());
39 IntrusiveRefCntPtr<DiagnosticIDs>
40 DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
41 for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
1
Assuming 'I' is not equal to 'N'
2
Loop condition is true. Entering loop body
6
Potential leak of memory pointed to by field 'Obj'
42 IntrusiveRefCntPtr<DiagnosticsEngine>
43 Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
3
Memory is allocated
44 new ForwardingDiagnosticConsumer(
45 *CI.getDiagnostics().getClient()),
46 /*ShouldOwnClient=*/true));
47 std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
48 ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
49 CI.getFileSystemOpts(), false);
50
51 if (!Unit)
4
Taking true branch
52 continue;
5
Execution continues on line 41
53
54 ASTImporter Importer(CI.getASTContext(),
55 CI.getFileManager(),
56 Unit->getASTContext(),
57 Unit->getFileManager(),
58 /*MinimalImport=*/false);
59
60 TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
61 for (auto *D : TU->decls()) {
62 // Don't re-import __va_list_tag, __builtin_va_list.
63 if (const auto *ND = dyn_cast<NamedDecl>(D))
64 if (IdentifierInfo *II = ND->getIdentifier())
65 if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
66 continue;
67
68 Decl *ToD = Importer.Import(D);
69
70 if (ToD) {
71 DeclGroupRef DGR(ToD);
72 CI.getASTConsumer().HandleTopLevelDecl(DGR);
73 }
74 }
75 }
76
77 AdaptedAction->ExecuteAction();
78 CI.getDiagnostics().getClient()->EndSourceFile();
79}
80
81void ASTMergeAction::EndSourceFileAction() {
82 return AdaptedAction->EndSourceFileAction();
83}
84
85ASTMergeAction::ASTMergeAction(std::unique_ptr<FrontendAction> adaptedAction,
86 ArrayRef<std::string> ASTFiles)
87: AdaptedAction(std::move(adaptedAction)), ASTFiles(ASTFiles.begin(), ASTFiles.end()) {
88 assert(AdaptedAction && "ASTMergeAction needs an action to adapt")(static_cast <bool> (AdaptedAction && "ASTMergeAction needs an action to adapt"
) ? void (0) : __assert_fail ("AdaptedAction && \"ASTMergeAction needs an action to adapt\""
, "/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Frontend/ASTMerge.cpp"
, 88, __extension__ __PRETTY_FUNCTION__))
;
89}
90
91ASTMergeAction::~ASTMergeAction() {
92}
93
94bool ASTMergeAction::usesPreprocessorOnly() const {
95 return AdaptedAction->usesPreprocessorOnly();
96}
97
98TranslationUnitKind ASTMergeAction::getTranslationUnitKind() {
99 return AdaptedAction->getTranslationUnitKind();
100}
101
102bool ASTMergeAction::hasPCHSupport() const {
103 return AdaptedAction->hasPCHSupport();
104}
105
106bool ASTMergeAction::hasASTFileSupport() const {
107 return AdaptedAction->hasASTFileSupport();
108}
109
110bool ASTMergeAction::hasCodeCompletionSupport() const {
111 return AdaptedAction->hasCodeCompletionSupport();
112}