From: Douglas Gregor Date: Thu, 27 Jan 2011 18:02:58 +0000 (+0000) Subject: Teach ASTUnit to save the specified target features, since X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1aa27307c462baaa9e5fda14ff6797dd39fe8b84;p=clang Teach ASTUnit to save the specified target features, since TargetInfo::CreateTargetInfo() mangles the target options in a way that is not idempotent. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124382 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index c971ccbc64..12555ab1af 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -84,6 +84,13 @@ private: /// LoadFromCommandLine available. llvm::OwningPtr Invocation; + /// \brief The set of target features. + /// + /// FIXME: each time we reparse, we need to restore the set of target + /// features from this vector, because TargetInfo::CreateTargetInfo() + /// mangles the target options in place. Yuck! + std::vector TargetFeatures; + // OnlyLocalDecls - when true, walking this AST should only visit declarations // that come from the AST itself, not from included precompiled headers. // FIXME: This is temporary; eventually, CIndex will always do this. diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index b8c27afe5f..9116d0ed17 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -740,6 +740,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) { Clang.setDiagnostics(&getDiagnostics()); // Create the target instance. + Clang.getTargetOpts().Features = TargetFeatures; Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(), Clang.getTargetOpts())); if (!Clang.hasTarget()) { @@ -1229,6 +1230,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( Clang.setDiagnostics(&getDiagnostics()); // Create the target instance. + Clang.getTargetOpts().Features = TargetFeatures; Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(), Clang.getTargetOpts())); if (!Clang.hasTarget()) { @@ -1418,6 +1420,9 @@ bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) { Invocation->getFrontendOpts().DisableFree = false; ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts()); + // Save the target features. + TargetFeatures = Invocation->getTargetOpts().Features; + llvm::MemoryBuffer *OverrideMainBuffer = 0; if (PrecompilePreamble) { PreambleRebuildCounter = 2; @@ -1876,6 +1881,7 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column, StoredDiagnostics); // Create the target instance. + Clang.getTargetOpts().Features = TargetFeatures; Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(), Clang.getTargetOpts())); if (!Clang.hasTarget()) { diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index be3a079598..808f4e9617 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -720,7 +720,7 @@ int perform_test_reparse_source(int argc, const char **argv, int trials, Idx = clang_createIndex(/* excludeDeclsFromPCH */ !strcmp(filter, "local") ? 1 : 0, - /* displayDiagnosics=*/1); + /* displayDiagnosics=*/0); if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) { clang_disposeIndex(Idx);