From: Douglas Gregor Date: Fri, 22 Jul 2011 06:03:18 +0000 (+0000) Subject: Fix an embarrassing bug in relocatable PCH support, where we were X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4947e25dd9f7ac1f2176d63262563ba3e96538fe;p=clang Fix an embarrassing bug in relocatable PCH support, where we were passing a temporary const char* down as the "isysroot" parameter and then accessing it later. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135749 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 4e2583db1e..1c5e365a23 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -632,6 +632,7 @@ protected: public: PCHGenerator(const Preprocessor &PP, const std::string &OutputFile, bool Chaining, const char *isysroot, raw_ostream *Out); + ~PCHGenerator(); virtual void InitializeSema(Sema &S) { SemaPtr = &S; } virtual void HandleTranslationUnit(ASTContext &Ctx); virtual ASTMutationListener *GetASTMutationListener(); diff --git a/lib/Serialization/GeneratePCH.cpp b/lib/Serialization/GeneratePCH.cpp index b8833ceacc..9cd694e05c 100644 --- a/lib/Serialization/GeneratePCH.cpp +++ b/lib/Serialization/GeneratePCH.cpp @@ -23,6 +23,8 @@ #include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/Support/raw_ostream.h" #include +#include +#include using namespace clang; @@ -31,7 +33,7 @@ PCHGenerator::PCHGenerator(const Preprocessor &PP, bool Chaining, const char *isysroot, llvm::raw_ostream *OS) - : PP(PP), OutputFile(OutputFile), isysroot(isysroot), Out(OS), SemaPtr(0), + : PP(PP), OutputFile(OutputFile), isysroot(0), Out(OS), SemaPtr(0), StatCalls(0), Stream(Buffer), Writer(Stream), Chaining(Chaining) { // Install a stat() listener to keep track of all of the stat() // calls. @@ -40,6 +42,13 @@ PCHGenerator::PCHGenerator(const Preprocessor &PP, // *after* the already installed ASTReader's stat cache. PP.getFileManager().addStatCache(StatCalls, /*AtBeginning=*/!Chaining); + + if (isysroot) + this->isysroot = strdup(isysroot); +} + +PCHGenerator::~PCHGenerator() { + free((void*)isysroot); } void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {