From a15940f0f2182bcf9f170a921dd9c8e9f1733533 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Thu, 22 Mar 2012 15:27:44 -0700 Subject: [PATCH] Fix pch --- clang.sup | 19 +++++++++++++ rdm/Indexer.cpp | 74 +++++++++++++++++++++++++++++++++++++------------ shared/Log.cpp | 10 +++++++ 3 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 clang.sup diff --git a/clang.sup b/clang.sup new file mode 100644 index 000000000..90b8415e9 --- /dev/null +++ b/clang.sup @@ -0,0 +1,19 @@ +{ + 1 + Memcheck:Cond + fun:_ZNK5clang4Expr21refersToVectorElementEv + obj:* +} + + +{ + 2 + Memcheck:Cond + fun:_ZNK5clang4Expr21refersToVectorElementEv +} +{ + 3 + Memcheck:Cond + fun:_ZNK5clang4Expr17isTemporaryObjectERNS_10ASTContextEPKNS_13CXXRecordDeclE +} + diff --git a/rdm/Indexer.cpp b/rdm/Indexer.cpp index 6504850fc..0a34812d3 100644 --- a/rdm/Indexer.cpp +++ b/rdm/Indexer.cpp @@ -191,6 +191,7 @@ class IndexerImpl QMutex implMutex; QWaitCondition implCond; QSet indexing; + QSet pchHeaderError; QByteArray path; int lastJobId; @@ -442,22 +443,29 @@ static inline QList extractPchFiles(const QList& args) if (nextIsPch) { nextIsPch = false; out.append(arg); - } else if (arg == "-include-pch") + } else if (arg == "-include-pch") { nextIsPch = true; + } } return out; } void IndexerJob::run() { - QList pchFiles = extractPchFiles(m_args); + QList args = m_args; + QList pchFiles = extractPchFiles(args); if (!pchFiles.isEmpty()) { QMutexLocker locker(&m_impl->implMutex); bool wait; do { wait = false; - foreach (const QByteArray& pchFile, pchFiles) { - if (m_impl->indexing.contains(pchFile)) { + foreach (const QByteArray &pchFile, pchFiles) { + if (m_impl->pchHeaderError.contains(pchFile)) { + int idx = args.indexOf(pchFile); + Q_ASSERT(idx > 0); + args.removeAt(idx); + args.removeAt(idx - 1); + } else if (m_impl->indexing.contains(pchFile)) { wait = true; break; } @@ -468,27 +476,43 @@ void IndexerJob::run() } while (wait); } - QVarLengthArray clangArgs(m_args.size()); + QVarLengthArray clangArgs(args.size()); QByteArray clangLine = "clang "; - bool nextIsPch = false; + bool nextIsPch = false, nextIsX = false; + QByteArray pchName; + bool isPch = false; int idx = 0; - foreach(const QByteArray& arg, m_args) { + foreach(const QByteArray& arg, args) { if (arg.isEmpty()) continue; + if (nextIsPch) { nextIsPch = false; Resource resource(arg, Resource::NoLock); pchFiles.append(resource.hashedFileName(Resource::AST)); clangArgs[idx++] = pchFiles.last().constData(); - } else { - clangArgs[idx++] = arg.constData(); - if (arg == "-include-pch") { - nextIsPch = true; - } + clangLine += pchFiles.last().constData(); + clangLine += " "; + continue; + } + + if (nextIsX) { + nextIsX = false; + isPch = (arg == "c++-header" || arg == "c-header"); } + clangArgs[idx++] = arg.constData(); clangLine += arg; clangLine += " "; + if (arg == "-include-pch") { + nextIsPch = true; + } else if (arg == "-x") { + nextIsX = true; + } + } + if (isPch) { + Resource resource(m_in, Resource::NoLock); + pchName = resource.hashedFileName(Resource::AST); } clangLine += m_in; @@ -497,11 +521,22 @@ void IndexerJob::run() clangArgs.data(), idx, 0, 0, CXTranslationUnit_Incomplete); log(1) << "loading unit" << clangLine << (unit != 0); + bool pchError = false; - if (unit) { + if (!unit) { + pchError = isPch; + error() << "got 0 unit for" << clangLine; + } else { clang_getInclusions(unit, inclusionVisitor, this); clang_visitChildren(clang_getTranslationUnitCursor(unit), indexVisitor, this); error() << "visiting" << m_in << m_references.size() << mSymbols.size(); + if (isPch) { + Q_ASSERT(!pchName.isEmpty()); + if (clang_saveTranslationUnit(unit, pchName.constData(), clang_defaultSaveOptions(unit)) != CXSaveError_None) { + error() << "Couldn't save pch file" << m_in << pchName; + pchError = true; + } + } clang_disposeTranslationUnit(unit); const QHash >::const_iterator end = m_references.end(); @@ -545,11 +580,16 @@ void IndexerJob::run() } m_impl->syncer->addSymbols(mSymbols); m_impl->syncer->addSymbolNames(mSymbolNames); - } else { - error() << "got 0 unit for" << m_in; } clang_disposeIndex(index); - + if (isPch) { + QMutexLocker locker(&m_impl->implMutex); + if (pchError) { + m_impl->pchHeaderError.insert(m_in); + } else { + m_impl->pchHeaderError.remove(m_in); + } + } emit done(m_id, m_in); } @@ -608,7 +648,7 @@ int Indexer::index(const QByteArray& input, const QList& arguments) if (!m_impl->timerRunning) { m_impl->timerRunning = true; - m_impl->timer.restart(); + m_impl->timer.start(); } QThreadPool::globalInstance()->start(job); diff --git a/shared/Log.cpp b/shared/Log.cpp index 7fcd05d9f..ad2085a71 100644 --- a/shared/Log.cpp +++ b/shared/Log.cpp @@ -26,6 +26,7 @@ static void log(int level, const char *format, va_list v) const QByteArray now = QDateTime::currentDateTime().toString("dd/MM/yy hh:mm:ss").toLocal8Bit(); static QMutex mutex; QMutexLocker lock(&mutex); // serialize +#if 0 static const char *names[] = { "Error: ", "Warning: ", "Debug: ", "Verbose: " }; const char *name = level < static_cast(sizeof(names)) / 4 ? names[level] : ""; if (level <= sLevel) @@ -34,6 +35,15 @@ static void log(int level, const char *format, va_list v) fprintf(sFile, "%s: %s%s\n", now.constData(), name, msg); fflush(sFile); } +#else + if (level <= sLevel) + fprintf(stderr, "%s: %s\n", now.constData(), msg); + if (sFile) { + fprintf(sFile, "%s: %s\n", now.constData(), msg); + fflush(sFile); + } +#endif + if (msg != buf) delete []msg; }