From 4981926bf654fe5a2c3893f24ca44106b217e71e Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 4 Jul 2009 13:58:54 +0000 Subject: Import Clang r74788. --- tools/clang-cc/clang-cc.cpp | 28 ++++++++++++++++++++++++---- tools/driver/driver.cpp | 2 +- tools/index-test/index-test.cpp | 7 +++++-- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index a3ffb48..9433c17 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -50,6 +50,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" +#include "llvm/LLVMContext.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" @@ -660,6 +661,11 @@ PICLevel("pic-level", llvm::cl::desc("Value for __PIC__")); static llvm::cl::opt StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined")); +static llvm::cl::opt +StackProtector("stack-protector", + llvm::cl::desc("Enable stack protectors"), + llvm::cl::init(-1)); + static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, TargetInfo *Target, const llvm::StringMap &Features) { @@ -779,6 +785,9 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, if (AccessControl) Options.AccessControl = 1; + // OpenCL and C++ both have bool, true, false keywords. + Options.Bool = Options.OpenCL | Options.CPlusPlus; + Options.MathErrno = MathErrno; Options.InstantiationDepth = TemplateDepth; @@ -814,6 +823,15 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, Options.Static = StaticDefine; + switch (StackProtector) { + default: + assert(StackProtector <= 2 && "Invalid value for -stack-protector"); + case -1: break; + case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break; + case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break; + case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break; + } + if (MainFileName.getPosition()) Options.setMainFileName(MainFileName.c_str()); } @@ -1729,7 +1747,8 @@ static llvm::raw_ostream* ComputeOutFile(const std::string& InFile, /// static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, const std::string &InFile, ProgActions PA, - const llvm::StringMap &Features) { + const llvm::StringMap &Features, + llvm::LLVMContext& Context) { llvm::OwningPtr OS; llvm::OwningPtr Consumer; bool ClearSourceMgr = false; @@ -1796,7 +1815,7 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, InitializeCompileOptions(Opts, PP.getLangOptions(), Features); Consumer.reset(CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(), Opts, InFile, - OS.get())); + OS.get(), Context)); break; } @@ -2088,9 +2107,10 @@ InputFilenames(llvm::cl::Positional, llvm::cl::desc("")); int main(int argc, char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc, argv); + llvm::LLVMContext Context; llvm::cl::ParseCommandLineOptions(argc, argv, "LLVM 'Clang' Compiler: http://clang.llvm.org\n"); - + llvm::InitializeAllTargets(); llvm::InitializeAllAsmPrinters(); @@ -2264,7 +2284,7 @@ int main(int argc, char **argv) { ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get()); // Process the source file. - ProcessInputFile(*PP, PPFactory, InFile, ProgAction, Features); + ProcessInputFile(*PP, PPFactory, InFile, ProgAction, Features, Context); HeaderInfo.ClearFileInfo(); DiagClient->setLangOptions(0); diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 804bef4..323283e 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -219,7 +219,7 @@ int main(int argc, const char **argv) { int Res = 0; if (C.get()) - Res = C->Execute(); + Res = TheDriver.ExecuteCompilation(*C); llvm::llvm_shutdown(); diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index 5606e75..552b7b0 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -125,16 +125,19 @@ int main(int argc, char **argv) { if (Point.D) { llvm::raw_ostream &OS = llvm::outs(); - assert(Point.D && "If no node was found we should have exited with error"); OS << "Declaration node at point: " << Point.D->getDeclKindName() << " "; if (NamedDecl *ND = dyn_cast(Point.D)) OS << ND->getNameAsString(); OS << "\n"; + if (const char *Comment = AST->getASTContext().getCommentForDecl(Point.D)) + OS << "Comment associated with this declaration:\n" << Comment << "\n"; + if (Point.Node) { OS << "Statement node at point: " << Point.Node->getStmtClassName() << " "; - Point.Node->printPretty(OS, AST->getASTContext()); + Point.Node->printPretty(OS, AST->getASTContext(), 0, + PrintingPolicy(AST->getASTContext().getLangOptions())); OS << "\n"; } } -- cgit v1.1