]> granicus.if.org Git - clang/commitdiff
Fix an embarrassing bug in relocatable PCH support, where we were
authorDouglas Gregor <dgregor@apple.com>
Fri, 22 Jul 2011 06:03:18 +0000 (06:03 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 22 Jul 2011 06:03:18 +0000 (06:03 +0000)
passing a temporary const char* down as the "isysroot" parameter and
then accessing it later. Fixes <rdar://problem/9035180>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135749 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTWriter.h
lib/Serialization/GeneratePCH.cpp

index 4e2583db1e83ed9f0b03f47d99dcdbed961162a6..1c5e365a23ddfc7cd2dd647283d5a2fa7a1befc1 100644 (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();
index b8833ceacc7eff648e738e9c985616ab6eca9964..9cd694e05c332c90f5c794bf10cd2f76cb920eb3 100644 (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) {