]> granicus.if.org Git - clang/commitdiff
[libclang] When loading an AST file, make sure to apply the language options
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 14 Sep 2012 20:24:53 +0000 (20:24 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 14 Sep 2012 20:24:53 +0000 (20:24 +0000)
to the target info.

Related to rdar://12069503.

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

lib/Frontend/ASTUnit.cpp
test/Index/index-pch.cpp [new file with mode: 0644]

index 42a67720c3532ec19184c5f8158ba82e451f5531..d0aadfd29ea97f6d1602ee3c77519177e43444c9 100644 (file)
@@ -525,6 +525,8 @@ public:
     Context.InitBuiltinTypes(*Target);
     
     InitializedLanguage = true;
+
+    applyLangOptsToTarget();
     return false;
   }
 
@@ -541,6 +543,8 @@ public:
     TargetOpts.Features.clear();
     TargetOpts.Triple = Triple;
     Target = TargetInfo::CreateTargetInfo(PP.getDiagnostics(), TargetOpts);
+
+    applyLangOptsToTarget();
     return false;
   }
 
@@ -562,6 +566,17 @@ public:
   virtual void ReadCounter(unsigned Value) {
     Counter = Value;
   }
+
+private:
+  void applyLangOptsToTarget() {
+    if (Target && InitializedLanguage) {
+      // Inform the target of the language options.
+      //
+      // FIXME: We shouldn't need to do this, the target should be immutable once
+      // created. This complexity should be lifted elsewhere.
+      Target->setForcedLangOptions(LangOpt);
+    }
+  }
 };
 
 class StoredDiagnosticConsumer : public DiagnosticConsumer {
diff --git a/test/Index/index-pch.cpp b/test/Index/index-pch.cpp
new file mode 100644 (file)
index 0000000..c8da7b2
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: c-index-test -write-pch %t.pch -fshort-wchar %s
+// RUN: c-index-test -index-tu %t.pch | FileCheck %s
+
+const wchar_t *wideStr = L"123";
+
+// CHECK: [indexDeclaration]: kind: variable | name: wideStr