[C++20] [Modules] Don't generate unused variables in other module units
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Sat, 6 May 2023 09:32:39 +0000 (17:32 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Wed, 10 May 2023 09:41:58 +0000 (17:41 +0800)
commitb6c7177145bc439c712208bfbe041db212c5262d
tree27a7403f1ba2e30e6afa385fed048ed0ac22ee33
parent7591a7b6ea5a36653c22fcec9aaf5c81ebab5bd1
[C++20] [Modules] Don't generate unused variables in other module units
even if its initializer has side effects

Close https://github.com/llvm/llvm-project/issues/61892

The variables whose initializer has side effects will be emitted even if
it is not used. But it shouldn't be true after we introduced modules.
The variables in other modules shouldn't be emitted if it is not used
even if its initializer has size effects.

Also this patch rename `Decl::isInCurrentModuleUnit` to
`Decl::isInAnotherModuleUnit` to make it closer to the semantics.
clang/include/clang/AST/DeclBase.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/Modules/pr61892.cppm [new file with mode: 0644]