]> granicus.if.org Git - clang/commitdiff
Teach ASTUnit to save the specified target features, since
authorDouglas Gregor <dgregor@apple.com>
Thu, 27 Jan 2011 18:02:58 +0000 (18:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 27 Jan 2011 18:02:58 +0000 (18:02 +0000)
TargetInfo::CreateTargetInfo() mangles the target options in a way
that is not idempotent. Fixes <rdar://problem/8807535>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124382 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
tools/c-index-test/c-index-test.c

index c971ccbc64098eb7bbe01df3d2ac647bf95a12b4..12555ab1affdbde5289118d4c2832ecfd8efa55f 100644 (file)
@@ -84,6 +84,13 @@ private:
   /// LoadFromCommandLine available.
   llvm::OwningPtr<CompilerInvocation> 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<std::string> 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.
index b8c27afe5fda07836ce84b6fda67378b3a92023e..9116d0ed1773c421eb3dcfbf9b3af37e3ea8e962 100644 (file)
@@ -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()) {
index be3a0795984d860052d59567d9937db22f02ade9..808f4e961713373f7f2e09f3b389cfd942394e29 100644 (file)
@@ -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);