[PATCH] D152274: [clang] Don't create import decls without -fmodules

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 07:45:03 PDT 2023


kadircet updated this revision to Diff 528863.
kadircet added a comment.

- Test layering check violation diagnostics


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,7 +636,7 @@
       TUKind == TU_Module &&
       getSourceManager().isWrittenInMainFile(DirectiveLoc);
 
-  bool ShouldAddImport = !IsInModuleIncludes;
+  bool ShouldAddImport = !IsInModuleIncludes && getLangOpts().Modules;
 
   // If this module import was due to an inclusion directive, create an
   // implicit import declaration to capture it in the AST.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152274.528863.patch
Type: text/x-patch
Size: 3057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230606/ca2ec706/attachment.bin>


More information about the cfe-commits mailing list