Files
clang-p2996/clang/test/Modules/submodule-visibility-pch.c
Ben Langmuir e06a91c599 [clang][modules] Avoid re-exporting PCH imports on every later module import
We only want to make PCH imports visible once for the the TU, not
repeatedly after every subsequent import. This causes some incorrect
behaviour with submodule visibility, and causes us to get extra module
dependencies in the scanner. So far I have only seen obviously incorrect
behaviour when building with -fmodule-name to cause a submodule to be
textually included when using the PCH, though the old behaviour seems
wrong regardless.

rdar://107449644

Differential Revision: https://reviews.llvm.org/D148176
2023-04-20 11:29:23 -07:00

57 lines
1.5 KiB
C

// Verify that the use of a PCH does not accidentally make modules from the PCH
// visible to submodules when using -fmodules-local-submodule-visibility
// and -fmodule-name to trigger a textual include.
// RUN: rm -rf %t
// RUN: split-file %s %t
// First check that it works with a header
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache \
// RUN: -fmodules-local-submodule-visibility -fimplicit-module-maps \
// RUN: -fmodule-name=Mod \
// RUN: %t/tu.c -include %t/prefix.h -I %t -verify
// Now with a PCH
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache \
// RUN: -fmodules-local-submodule-visibility -fimplicit-module-maps \
// RUN: -x c-header %t/prefix.h -emit-pch -o %t/prefix.pch -I %t
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache \
// RUN: -fmodules-local-submodule-visibility -fimplicit-module-maps \
// RUN: -fmodule-name=Mod \
// RUN: %t/tu.c -include-pch %t/prefix.pch -I %t -verify
//--- module.modulemap
module ModViaPCH { header "ModViaPCH.h" }
module ModViaInclude { header "ModViaInclude.h" }
module Mod { header "Mod.h" }
module SomeOtherMod { header "SomeOtherMod.h" }
//--- ModViaPCH.h
#define ModViaPCH 1
//--- ModViaInclude.h
#define ModViaInclude 2
//--- SomeOtherMod.h
// empty
//--- Mod.h
#include "SomeOtherMod.h"
#ifdef ModViaPCH
#error "Visibility violation ModViaPCH"
#endif
#ifdef ModViaInclude
#error "Visibility violation ModViaInclude"
#endif
//--- prefix.h
#include "ModViaPCH.h"
//--- tu.c
#include "ModViaInclude.h"
#include "Mod.h"
// expected-no-diagnostics