160 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir %t3 4// RUN: not %clang_cc1 -fmodules -fmodule-name=file -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E 2>&1 | FileCheck %s --check-prefix=MISSING-FWD5// MISSING-FWD: module 'fwd' is needed6 7// RUN: %clang_cc1 -fmodules -fmodule-name=fwd -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -emit-module -o %t/fwd.pcm8 9// Check that we can preprocess modules, and get the expected output.10// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -o %t/no-rewrite.ii11// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes -o %t/rewrite.ii12//13// RUN: FileCheck %s --input-file %t/no-rewrite.ii --check-prefix=CHECK --check-prefix=NO-REWRITE14// RUN: FileCheck %s --input-file %t/rewrite.ii --check-prefix=CHECK --check-prefix=REWRITE15 16// Check that we can build a module from the preprocessed output.17// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm18// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm19 20// Check that we can load the original module map in the same compilation (this21// could happen if we had a redundant -fmodule-map-file= in the original22// build).23// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -fmodule-map-file=%S/Inputs/preprocess/module.modulemap -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o /dev/null24 25// Check the module we built works.26// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery27// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE28// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DINCLUDE -I%S/Inputs/preprocess29// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess30 31// Now try building the module when the header files are missing.32// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t33// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%t -x c++-module-map %t/module.modulemap -E -frewrite-includes -o %t/copy.ii34// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap35// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/copy.ii -emit-module -o %t/copy.pcm36 37// Check that our module contains correct mapping information for the headers.38// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t39// RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE40// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap41 42// Check that we can preprocess from a .pcm file and that we get the same result as preprocessing from the original sources.43// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -emit-module -o %t/file.pcm44// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii45// FIXME: This check fails on Windows targets, due to canonicalization of directory separators.46// FIXME: cmp %t/rewrite.ii %t/file.rewrite.ii47// FIXME: Instead, just check that the preprocessed output is functionally equivalent to the output when preprocessing from the original sources.48// RUN: FileCheck %s --input-file %t/file.rewrite.ii --check-prefix=CHECK --check-prefix=REWRITE49// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/file.rewrite.ii -emit-module -o %t/file.rewrite.pcm50// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE51// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE -DINCLUDE -I%S/Inputs/preprocess52//53// Check that we can preprocess this user of the .pcm file.54// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E -frewrite-imports -DFILE_REWRITE_FULL -o %t/preprocess-module.ii55// RUN: %clang_cc1 -fmodules %t/preprocess-module.ii -verify -fno-modules-error-recovery -DFILE_REWRITE_FULL56//57// Check that language / header search options are ignored when preprocessing from a .pcm file.58// RUN: %clang_cc1 %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii.259// RUN: cmp %t/file.rewrite.ii %t/file.rewrite.ii.260//61// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess %t/file.pcm -E -o %t/file.no-rewrite.ii62// RUN: %clang_cc1 %t/file.pcm -E -o %t/file.no-rewrite.ii.2 -Dstruct=error63// RUN: cmp %t/file.no-rewrite.ii %t/file.no-rewrite.ii.264 65// == module map66// CHECK: # 1 "{{.*}}module.modulemap"67// CHECK: module file {68// CHECK: header "file.h" { size69// CHECK: header "file2.h" { size70// CHECK: }71 72// == file.h73// CHECK: # 1 "<module-includes>"74// REWRITE: #if defined(__CLANG_REWRITTEN_INCLUDES)75// REWRITE: #include "file.h"76// REWRITE: #else /* file.h expanded by -frewrite-includes77//78// FIXME: It would be preferable to consistently put the module begin/end in79// the same file, but the relative ordering of PP callbacks and module80// begin/end tokens makes that difficult.81//82// REWRITE: #pragma clang module begin file83// CHECK: # 1 "{{.*}}file.h" 184// NO-REWRITE: #pragma clang module begin file85//86// REWRITE: #ifndef FILE_H87// REWRITE: #define FILE_H88//89// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import90// CHECK: typedef struct __FILE FILE;91//92// REWRITE: #endif93//94// REWRITE: #pragma clang module end95// CHECK: # 2 "<module-includes>" 296// NO-REWRITE: #pragma clang module end97 98// == file2.h99// REWRITE: #if defined(__CLANG_REWRITTEN_INCLUDES)100// REWRITE: #include "file2.h"101// REWRITE: #else /* file2.h expanded102//103// REWRITE: #pragma clang module begin file104// CHECK: # 1 "{{.*}}file2.h" 1105// NO-REWRITE: #pragma clang module begin file106//107// ==== recursively re-enter file.h108// REWRITE: #if defined(__CLANG_REWRITTEN_INCLUDES)109// REWRITE: #include "file.h"110// REWRITE: #else /* file.h expanded111//112// REWRITE: #pragma clang module begin file113// CHECK: # 1 "{{.*}}file.h" 1114// NO-REWRITE: #pragma clang module begin file115//116// REWRITE: #ifndef FILE_H117// REWRITE: #define FILE_H118// REWRITE: #if 0119// REWRITE: #include "fwd.h"120// REWRITE: #endif121// REWRITE-NOT: #pragma clang module import fwd122// REWRITE: #endif123//124// NO-REWRITE-NOT: struct __FILE;125//126// REWRITE: #pragma clang module end127// CHECK: # 2 "{{.*}}file2.h" 2128// NO-REWRITE: #pragma clang module end129// NO-REWRITE: # 2 "{{.*}}file2.h"{{$}}130// ==== return to file2.h131//132// CHECK: extern int file2;133//134// REWRITE: #pragma clang module end135// CHECK: # 3 "<module-includes>" 2136// NO-REWRITE: #pragma clang module end137 138 139__FILE *a; // expected-error-re {{{{declaration of '__FILE' must be imported|unknown type name '__FILE'}}}}140#if FILE_REWRITE141// expected-note@file.rewrite.ii:* {{here}}142#elif FILE_REWRITE_FULL143// No note diagnostic at all in this case: we've built the 'file' module but not loaded it into this compilation yet.144#elif REWRITE145// expected-note@rewrite.ii:* {{here}}146#elif COPY147// expected-note@copy.ii:* {{here}}148#else149// expected-note@no-rewrite.ii:* {{here}}150#endif151 152#ifdef INCLUDE153#include "file.h"154#else155#pragma clang module import file156#endif157 158FILE *b;159int x = file2; // ok, found in file2.h, even under -DINCLUDE160