From: Chris Lattner Date: Fri, 14 Mar 2008 06:12:05 +0000 (+0000) Subject: Only compute targetinfo once and don't leak it. Patch by Sam Bishop! X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1121519f279d0e2168dbcb6428f8e274fd46e9be;p=clang Only compute targetinfo once and don't leak it. Patch by Sam Bishop! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48358 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 5f3f168ff7..c004d9d6b1 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -1262,6 +1262,16 @@ int main(int argc, char **argv) { --i; } } + + // Get information about the target being compiled for. + std::string Triple = CreateTargetTriple(); + TargetInfo *Target = TargetInfo::CreateTargetInfo(Triple); + if (Target == 0) { + fprintf(stderr, "Sorry, I don't know what target this is: %s\n", + Triple.c_str()); + fprintf(stderr, "Please use -triple or -arch.\n"); + exit(1); + } for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; @@ -1285,19 +1295,6 @@ int main(int argc, char **argv) { DiagClient->setHeaderSearch(HeaderInfo); InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo); - // Get information about the targets being compiled for. Note that this - // pointer and the TargetInfoImpl objects are never deleted by this toy - // driver. - std::string Triple = CreateTargetTriple(); - TargetInfo *Target = TargetInfo::CreateTargetInfo(Triple); - - if (Target == 0) { - fprintf(stderr, "Sorry, I don't know what target this is: %s\n", - Triple.c_str()); - fprintf(stderr, "Please use -triple or -arch.\n"); - exit(1); - } - // Set up the preprocessor with these options. Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo); @@ -1313,6 +1310,8 @@ int main(int argc, char **argv) { } } + delete Target; + unsigned NumDiagnostics = Diags.getNumDiagnostics(); if (NumDiagnostics)