Allow getStringType() to reset the cache.

This commit is contained in:
Axel Naumann 2017-06-23 10:46:37 +02:00 committed by sftnight
parent 7825094907
commit aae2870f62
2 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
#include <array>
#include <memory>
namespace clang {
@ -57,7 +58,7 @@ namespace cling {
private:
std::unique_ptr<clang::Parser> m_Parser;
Interpreter* m_Interpreter; // we do not own.
const clang::Type* m_StringTy[kNumCachedStrings] = {};
std::array<const clang::Type*, kNumCachedStrings> m_StringTy = {};
public:
LookupHelper(clang::Parser* P, Interpreter* interp);

View File

@ -1910,6 +1910,10 @@ namespace cling {
assert(Type && "Type cannot be null");
const Transaction*& Cache = m_Interpreter->getStdStringTransaction();
if (!Cache || !m_StringTy[kStdString]) {
// getStringType can be called multiple times with Cache being null, and
// the local cache should be discarded when that occurs.
if (!Cache)
m_StringTy = {};
QualType Qt = findType("std::string", WithDiagnostics);
m_StringTy[kStdString] = Qt.isNull() ? nullptr : Qt.getTypePtr();
if (!m_StringTy[kStdString]) return kNotAString;