summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-11-17 23:01:24 +0000
committerTed Kremenek <kremenek@apple.com>2011-11-17 23:01:24 +0000
commit8cf47df72f999b0adaeded4b2190978bc992ffc5 (patch)
treebab5bff7943e840647820feb4e46f76c89f2fadd /clang/lib/Frontend/CompilerInvocation.cpp
parent250476021f5ab554cc4eb245a6ccfe7bc1236281 (diff)
downloadbcm5719-llvm-8cf47df72f999b0adaeded4b2190978bc992ffc5.tar.gz
bcm5719-llvm-8cf47df72f999b0adaeded4b2190978bc992ffc5.zip
Make 'LangOptions' in CompilerInvocation a heap-allocated, reference counted object. I discovered that llvm::RefCountedBase<T> has
a bug where the reference count is copied in the copy constructor, which means that there were cases when the CompilerInvocation objects created by ASTUnit were actually leaked. When I fixed that bug locally, it showed that a whole bunch of code assumed that the LangOptions object that was part of CompilerInvocation was still alive. By making it heap-allocated and reference counted, we can keep it around after the CompilerInvocation object goes away. As part of this change, change CompilerInvocation:getLangOptions() to return a pointer, acting as another clue that this object may outlive the CompilerInvocation object. This commit doesn't fix the CompilerInvocation leak itself. That will come when I commit the fix to llvm::RefCountedBase<T> to mainline LLVM. llvm-svn: 144930
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 1fd967ffcc3..13be408141c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -30,6 +30,21 @@
#include "llvm/Support/Path.h"
using namespace clang;
+//===----------------------------------------------------------------------===//
+// Initialization.
+//===----------------------------------------------------------------------===//
+
+CompilerInvocation::CompilerInvocation()
+ : LangOpts(new LangOptions()) {}
+
+void CompilerInvocation::setLangOpts(LangOptions *LOpts) {
+ LangOpts = LOpts;
+}
+
+//===----------------------------------------------------------------------===//
+// Utility functions.
+//===----------------------------------------------------------------------===//
+
static const char *getAnalysisStoreName(AnalysisStores Kind) {
switch (Kind) {
default:
@@ -892,7 +907,7 @@ void CompilerInvocation::toArgs(std::vector<std::string> &Res) {
FileSystemOptsToArgs(getFileSystemOpts(), Res);
FrontendOptsToArgs(getFrontendOpts(), Res);
HeaderSearchOptsToArgs(getHeaderSearchOpts(), Res);
- LangOptsToArgs(getLangOpts(), Res);
+ LangOptsToArgs(*getLangOpts(), Res);
PreprocessorOptsToArgs(getPreprocessorOpts(), Res);
PreprocessorOutputOptsToArgs(getPreprocessorOutputOpts(), Res);
TargetOptsToArgs(getTargetOpts(), Res);
@@ -1982,9 +1997,9 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags);
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args);
if (DashX != IK_AST && DashX != IK_LLVM_IR) {
- ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags);
+ ParseLangArgs(*Res.getLangOpts(), *Args, DashX, Diags);
if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
- Res.getLangOpts().ObjCExceptions = 1;
+ Res.getLangOpts()->ObjCExceptions = 1;
}
// FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
// PCH file and find the original header name. Remove the need to do that in
@@ -2057,9 +2072,9 @@ std::string CompilerInvocation::getModuleHash() const {
// Extend the signature with the language options
#define LANGOPT(Name, Bits, Default, Description) \
- Signature.add(LangOpts.Name, Bits);
+ Signature.add(LangOpts->Name, Bits);
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
- Signature.add(static_cast<unsigned>(LangOpts.get##Name()), Bits);
+ Signature.add(static_cast<unsigned>(LangOpts->get##Name()), Bits);
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
#include "clang/Basic/LangOptions.def"
OpenPOWER on IntegriCloud