diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-11-05 23:58:27 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-11-05 23:58:27 +0000 |
commit | c7be10245e78bf38694b26f289880edefb9f16e9 (patch) | |
tree | 2e56a05550ccb3fa371e14bbe188ac404b1d4cd7 | |
parent | 3043175274899e086c8664fe64c8fb4b9eacb733 (diff) |
Have the parser initialize Sema before it consumes the first
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
-rw-r--r-- | lib/CodeGen/CodeGenAction.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseAST.cpp | 1 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 8 | ||||
-rw-r--r-- | test/Modules/Inputs/Module.framework/Headers/Module.h | 2 | ||||
-rw-r--r-- | test/Modules/direct-module-import.m | 7 |
5 files changed, 17 insertions, 5 deletions
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index dd32167b84..1c536a6970 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -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; } diff --git a/lib/Parse/ParseAST.cpp b/lib/Parse/ParseAST.cpp index bd4f859521..7d68e1f37e 100644 --- a/lib/Parse/ParseAST.cpp +++ b/lib/Parse/ParseAST.cpp @@ -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 diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index e6b49474f7..7bf4220199 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -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 { diff --git a/test/Modules/Inputs/Module.framework/Headers/Module.h b/test/Modules/Inputs/Module.framework/Headers/Module.h index f8949848bd..3d2476b204 100644 --- a/test/Modules/Inputs/Module.framework/Headers/Module.h +++ b/test/Modules/Inputs/Module.framework/Headers/Module.h @@ -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 index 0000000000..317d7aea16 --- /dev/null +++ b/test/Modules/direct-module-import.m @@ -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(); +} |