summaryrefslogtreecommitdiffstats
path: root/clang/Driver
diff options
context:
space:
mode:
Diffstat (limited to 'clang/Driver')
-rw-r--r--clang/Driver/CacheTokens.cpp23
-rw-r--r--clang/Driver/clang.cpp31
2 files changed, 39 insertions, 15 deletions
diff --git a/clang/Driver/CacheTokens.cpp b/clang/Driver/CacheTokens.cpp
index 2548d3d7ddf..d791e09d6c2 100644
--- a/clang/Driver/CacheTokens.cpp
+++ b/clang/Driver/CacheTokens.cpp
@@ -24,6 +24,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Streams.h"
using namespace clang;
@@ -179,8 +180,20 @@ public:
CompareIDDataIndex(IDData* table) : Table(table) {}
bool operator()(unsigned i, unsigned j) const {
- // Assume that IdentifierInfo::getName() returns a '\0' terminated string.
- return strcmp(Table[i].II->getName(), Table[j].II->getName()) < 0;
+ const IdentifierInfo* II_i = Table[i].II;
+ const IdentifierInfo* II_j = Table[j].II;
+
+ unsigned i_len = II_i->getLength();
+ unsigned j_len = II_j->getLength();
+
+ if (i_len > j_len)
+ return false;
+
+ if (i_len < j_len)
+ return true;
+
+ // Otherwise, compare the strings themselves!
+ return strncmp(II_i->getName(), II_j->getName(), i_len) < 0;
}
};
}
@@ -221,7 +234,10 @@ PTHWriter::EmitIdentifierTable() {
unsigned len = d.II->getLength(); // Write out the string length.
Emit32(len);
const char* buf = d.II->getName(); // Write out the string data.
- EmitBuf(buf, buf+len);
+ EmitBuf(buf, buf+len);
+ // Emit a null character for those clients expecting that IdentifierInfo
+ // strings are null terminated.
+ Emit8('\0');
}
// Now emit the table mapping from persistent IDs to PTH file offsets.
@@ -229,7 +245,6 @@ PTHWriter::EmitIdentifierTable() {
Emit32(idcount); // Emit the number of identifiers.
for (unsigned i = 0 ; i < idcount; ++i) Emit32(IIDMap[i].FileOffset);
-
return std::make_pair(DataOff, std::make_pair(IDOff, LexicalOff));
}
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp
index c5aac3773e0..b7aea6799ea 100644
--- a/clang/Driver/clang.cpp
+++ b/clang/Driver/clang.cpp
@@ -955,12 +955,6 @@ static bool InitializePreprocessor(Preprocessor &PP,
PredefineBuffer.push_back(0);
PP.setPredefines(&PredefineBuffer[0]);
- // Use PTH.
- if (!TokenCache.empty()) {
- PTHManager* PM = PTHManager::Create(TokenCache, PP);
- if (PM) PP.setPTHManager(PM);
- }
-
// Once we've read this, we're done.
return false;
}
@@ -1142,18 +1136,33 @@ public:
virtual ~DriverPreprocessorFactory() {}
virtual Preprocessor* CreatePreprocessor() {
- Preprocessor* PP = new Preprocessor(Diags, LangInfo, Target,
- SourceMgr, HeaderInfo);
+ llvm::OwningPtr<PTHManager> PTHMgr;
+
+ // Use PTH?
+ if (!TokenCache.empty())
+ PTHMgr.reset(PTHManager::Create(TokenCache));
+
+ // Create the Preprocessor.
+ llvm::OwningPtr<Preprocessor> PP(new Preprocessor(Diags, LangInfo, Target,
+ SourceMgr, HeaderInfo,
+ PTHMgr.get()));
+
+ // Note that this is different then passing PTHMgr to Preprocessor's ctor.
+ // That argument is used as the IdentifierInfoLookup argument to
+ // IdentifierTable's ctor.
+ if (PTHMgr) {
+ PTHMgr->setPreprocessor(PP.get());
+ PP->setPTHManager(PTHMgr.take());
+ }
if (InitializePreprocessor(*PP, InitializeSourceMgr, InFile)) {
- delete PP;
return NULL;
}
/// FIXME: PP can only handle one callback
if (ProgAction != PrintPreprocessedInput) {
const char* ErrStr;
- bool DFG = CreateDependencyFileGen(PP, OutputFile, InFile, ErrStr);
+ bool DFG = CreateDependencyFileGen(PP.get(), OutputFile, InFile, ErrStr);
if (!DFG && ErrStr) {
fprintf(stderr, "%s", ErrStr);
return NULL;
@@ -1161,7 +1170,7 @@ public:
}
InitializeSourceMgr = false;
- return PP;
+ return PP.take();
}
};
}
OpenPOWER on IntegriCloud