Author: Chuanqi Xu Date: 2022-09-18T16:43:30+08:00 New Revision: 762962174e3adab1a0d744fe2636d4d9fb373c53
URL: https://github.com/llvm/llvm-project/commit/762962174e3adab1a0d744fe2636d4d9fb373c53 DIFF: https://github.com/llvm/llvm-project/commit/762962174e3adab1a0d744fe2636d4d9fb373c53.diff LOG: [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. Added: clang/test/SemaCXX/PR57778.cpp Modified: clang/include/clang/Basic/LangOptions.h clang/lib/Parse/ParseAST.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index dd2a7920a5f1..9facfb0beba2 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -113,7 +113,7 @@ class LangOptions : public LangOptionsBase { /// 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 @@ class LangOptions : public LangOptionsBase { 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; diff --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp index 5fca029a4266..2e6d7eea4677 100644 --- a/clang/lib/Parse/ParseAST.cpp +++ b/clang/lib/Parse/ParseAST.cpp @@ -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(); diff --git a/clang/test/SemaCXX/PR57778.cpp b/clang/test/SemaCXX/PR57778.cpp new file mode 100644 index 000000000000..260dd7c97976 --- /dev/null +++ b/clang/test/SemaCXX/PR57778.cpp @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits