[Modules] Don't judge if we're compiling a module unit by LangOpts::CurrentModule.empty()
Closing https://github.com/llvm/llvm-project/issues/57778. Previously it judge if we're compiling a module unit by LangOpts::CurrentModule.empty(). But it is not true since we can specify the module name by `-fmodule-name` option for arbitrary module unit. Then this patch adjuest the judgement properly.
This commit is contained in:
parent
b987fe4972
commit
762962174e
|
@ -113,7 +113,7 @@ public:
|
|||
/// Compiling a module header unit.
|
||||
CMK_HeaderUnit,
|
||||
|
||||
/// Compiling a C++ modules TS module interface unit.
|
||||
/// Compiling a C++ modules interface unit.
|
||||
CMK_ModuleInterface,
|
||||
};
|
||||
|
||||
|
@ -495,11 +495,16 @@ public:
|
|||
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
|
||||
#include "clang/Basic/LangOptions.def"
|
||||
|
||||
/// Are we compiling a module interface (.cppm or module map)?
|
||||
/// Are we compiling a module?
|
||||
bool isCompilingModule() const {
|
||||
return getCompilingModule() != CMK_None;
|
||||
}
|
||||
|
||||
/// Are we compiling a standard c++ module interface?
|
||||
bool isCompilingModuleInterface() const {
|
||||
return getCompilingModule() == CMK_ModuleInterface;
|
||||
}
|
||||
|
||||
/// Do we need to track the owning module for a local declaration?
|
||||
bool trackLocalOwningModule() const {
|
||||
return isCompilingModule() || ModulesLocalVisibility;
|
||||
|
|
|
@ -177,7 +177,7 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
|
|||
|
||||
// At this point, we should know if we are building a non-header C++20 module.
|
||||
if (S.getLangOpts().CPlusPlusModules && !S.getLangOpts().IsHeaderFile &&
|
||||
!S.getLangOpts().CurrentModule.empty()) {
|
||||
S.getLangOpts().isCompilingModuleInterface()) {
|
||||
// If we are building the module from source, then the top level module
|
||||
// will be here.
|
||||
Module *CodegenModule = S.getCurrentModule();
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: %clang_cc1 -std=c++20 -fmodule-name=test -fsyntax-only %s -verify
|
||||
// expected-no-diagnostics
|
||||
|
||||
// Ensure that we won't crash if we specified `-fmodule-name` in `c++20`
|
||||
// for a non module unit.
|
||||
int a;
|
Loading…
Reference in New Issue