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 <rdar://problem/9035180>.

llvm-svn: 135749
This commit is contained in:
Douglas Gregor 2011-07-22 06:03:18 +00:00
parent 4dd6c043ae
commit 77d993d3aa
2 changed files with 11 additions and 1 deletions

View File

@ -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();

View File

@ -23,6 +23,8 @@
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <string.h>
#include <stdlib.h>
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) {