[PATCH] D152274: [clang] Don't create import decls without -fmodules
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 16 00:26:57 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d0cfa6d09e2: [clang] Don't create import decls without -fmodules (authored by kadircet).
Changed prior to commit:
https://reviews.llvm.org/D152274?vs=528863&id=532012#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152274/new/
https://reviews.llvm.org/D152274
Files:
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/Inputs/modulemaps-nomodules/header.h
clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
clang/test/Modules/getSourceDescriptor-crash.cpp
clang/test/Modules/modulemaps-nomodules.cpp
clang/test/PCH/Inputs/modulemaps-nomodules/header.h
clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
clang/test/PCH/modulemaps-nomodules.cpp
Index: clang/test/PCH/modulemaps-nomodules.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/modulemaps-nomodules.cpp
@@ -0,0 +1,6 @@
+// Make sure we don't crash when serializing a PCH with an include from a
+// modulemap file in nomodules mode.
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules -fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -emit-pch -o /dev/null
+
+#include "header.h"
Index: clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
===================================================================
--- /dev/null
+++ clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+ header "header.h"
+}
Index: clang/test/Modules/modulemaps-nomodules.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/modulemaps-nomodules.cpp
@@ -0,0 +1,8 @@
+// Make sure we treat includes that are part of modulemaps the same as textual
+// headers when modules are not enabled (e.g do't generate import decls, but
+// still perform layering checks).
+// No need to pass -fno-modules explicitly, absence implies negation for cc1.
+// RUN: %clang_cc1 -I %S/Inputs/modulemaps-nomodules -fmodule-map-file=%S/Inputs/modulemaps-nomodules/module.modulemap %s -verify -ast-dump | FileCheck %s
+
+#include "header.h" // expected-error{{use of private header from outside its module: 'header.h'}}
+// CHECK-NOT: ImportDecl
Index: clang/test/Modules/getSourceDescriptor-crash.cpp
===================================================================
--- clang/test/Modules/getSourceDescriptor-crash.cpp
+++ clang/test/Modules/getSourceDescriptor-crash.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm -debug-info-kind=limited -debugger-tuning=lldb -fimplicit-module-maps %s -o - | FileCheck %s
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -I %S/Inputs/getSourceDescriptor-crash -S -emit-llvm -debug-info-kind=limited -debugger-tuning=lldb -fmodules -fmodules-cache-path=%t -fimplicit-module-maps %s -o - | FileCheck %s
#include "h1.h"
#include "h1.h"
Index: clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+ private header "header.h"
+}
Index: clang/lib/Sema/SemaModule.cpp
===================================================================
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -636,11 +636,9 @@
TUKind == TU_Module &&
getSourceManager().isWrittenInMainFile(DirectiveLoc);
- bool ShouldAddImport = !IsInModuleIncludes;
-
- // If this module import was due to an inclusion directive, create an
- // implicit import declaration to capture it in the AST.
- if (ShouldAddImport) {
+ // If we are really importing a module (not just checking layering) due to an
+ // #include in the main file, synthesize an ImportDecl.
+ if (getLangOpts().Modules && !IsInModuleIncludes) {
TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
DirectiveLoc, Mod,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152274.532012.patch
Type: text/x-patch
Size: 3428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230616/f17a602e/attachment.bin>
More information about the cfe-commits
mailing list