[modules] Don't emit initializers for VarDecls within a module eagerly whenever
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 20 Jul 2016 19:10:16 +0000 (19:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 20 Jul 2016 19:10:16 +0000 (19:10 +0000)
commitdc1f042171d93709952aeaa1c83bf91c0cf8a1be
treea504aefcca00d128754cdcfb479bf7cabd423e87
parent62ae568bbb9c4d22d341a71d12ab0bc74506476c
[modules] Don't emit initializers for VarDecls within a module eagerly whenever
we first touch any part of that module. Instead, defer them until the first
time that module is (transitively) imported. The initializer step for a module
then recursively initializes modules that its own headers imported.

For example, this avoids running the <iostream> global initializer in programs
that don't actually use iostreams, but do use other parts of the standard
library.

llvm-svn: 276159
19 files changed:
clang/include/clang/AST/ASTContext.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/Inputs/unused-global-init/init.h [new file with mode: 0644]
clang/test/Modules/Inputs/unused-global-init/module.modulemap [new file with mode: 0644]
clang/test/Modules/Inputs/unused-global-init/other.h [new file with mode: 0644]
clang/test/Modules/Inputs/unused-global-init/unused.h [new file with mode: 0644]
clang/test/Modules/Inputs/unused-global-init/used.h [new file with mode: 0644]
clang/test/Modules/odr.cpp
clang/test/Modules/templates.mm
clang/test/Modules/unused-global-init.cpp [new file with mode: 0644]