]> granicus.if.org Git - clang/commitdiff
Have the parser initialize Sema before it consumes the first
authorDouglas Gregor <dgregor@apple.com>
Mon, 5 Nov 2012 23:58:27 +0000 (23:58 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 5 Nov 2012 23:58:27 +0000 (23:58 +0000)
token. This is important because the first token could actually be
after an #include that triggers a module import, which might use
either Sema or the AST consumer before it would have been initialized.

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

lib/CodeGen/CodeGenAction.cpp
lib/Parse/ParseAST.cpp
lib/Parse/Parser.cpp
test/Modules/Inputs/Module.framework/Headers/Module.h
test/Modules/direct-module-import.m [new file with mode: 0644]

index dd32167b84779132af3c043e2e4d159ef7d1045f..1c536a6970338047a3fccfd047b8a54dec186f69 100644 (file)
@@ -65,9 +65,11 @@ namespace clang {
       TargetOpts(targetopts),
       LangOpts(langopts),
       AsmOutStream(OS),
+      Context(), 
       LLVMIRGeneration("LLVM IR Generation Time"),
       Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)),
-      LinkModule(LinkModule) {
+      LinkModule(LinkModule)
+    {
       llvm::TimePassesIsEnabled = TimePasses;
     }
 
index bd4f859521202232be557c720f390c95045b9a08..7d68e1f37e407acf5b0db7c42e999943333bdd51 100644 (file)
@@ -78,7 +78,6 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
 
   S.getPreprocessor().EnterMainSourceFile();
   P.Initialize();
-  S.Initialize();
 
   // C11 6.9p1 says translation units must have at least one top-level
   // declaration. C++ doesn't have this restriction. We also don't want to
index e6b49474f796ea9f03f94a2dcaa425bc2348c79b..7bf4220199986fe4d229b9d603cd8d0ef1ac301e 100644 (file)
@@ -470,9 +470,6 @@ void Parser::Initialize() {
   EnterScope(Scope::DeclScope);
   Actions.ActOnTranslationUnitScope(getCurScope());
 
-  // Prime the lexer look-ahead.
-  ConsumeToken();
-
   // Initialization for Objective-C context sensitive keywords recognition.
   // Referenced in Parser::ParseObjCTypeQualifierList.
   if (getLangOpts().ObjC1) {
@@ -527,6 +524,11 @@ void Parser::Initialize() {
     PP.SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block);
     PP.SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block);
   }
+
+  Actions.Initialize();
+
+  // Prime the lexer look-ahead.
+  ConsumeToken();
 }
 
 namespace {
index f8949848bd4c90c287f07a2562cb7a555bf5c6d4..3d2476b20431de5e6038923a688daf25f6a4ca7f 100644 (file)
@@ -23,4 +23,6 @@ const char *getModuleVersion(void);
 #include <Module/Sub.h>
 #include <Module/Buried/Treasure.h>
 
+__asm("foo");
+
 #endif // MODULE_H
diff --git a/test/Modules/direct-module-import.m b/test/Modules/direct-module-import.m
new file mode 100644 (file)
index 0000000..317d7ae
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-cache-path %t -fmodules -F %S/Inputs -include Module/Module.h %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: call i8* @getModuleVersion
+const char* getVer(void) {
+  return getModuleVersion();
+}