
This patch is part of a series to support driver managed module builds for C++ named modules and Clang modules. This introduces a scanner that detects C++ named module usage early in the driver with only negligible overhead. For now, it is enabled only with the `-fmodules-driver` flag and serves solely diagnostic purposes. In the future, the scanner will be enabled for any (modules-driver compatible) compilation with two or more inputs, and will help the driver determine whether to implicitly enable the modules driver. Since the scanner adds very little overhead, we are also exploring enabling it for compilations with only a single input. This approach could allow us to detect `import std` usage in a single-file compilation, which would then activate the modules driver. For performance measurements on this, see https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark. RFC for driver managed module builds: https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system This patch relands the reland (2d31fc8) for commit ded1426. The earlier reland failed due to a missing link dependency on `clangLex`. This reland fixes the issue by adding the link dependency after discussing it in the following RFC: https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex
193 lines
7.7 KiB
C++
193 lines
7.7 KiB
C++
// The driver never checks to implicitly enable the explicit module build
|
|
// support unless at least two input files are provided.
|
|
// To trigger the C++20 module usage check, we always pass a second dummy file
|
|
// as input.
|
|
// TODO: Remove -fmodules everywhere once implicitly enabled explicit module
|
|
// builds are supported.
|
|
|
|
// RUN: split-file %s %t
|
|
//--- empty.cpp
|
|
// Nothing here
|
|
|
|
//--- only-global.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/only-global.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK1
|
|
// CHECK1: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
module;
|
|
|
|
//--- only-import.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/only-import.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK2
|
|
// CHECK2: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
import A;
|
|
|
|
//--- only-export.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/only-export.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK3
|
|
// CHECK3: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
export module A;
|
|
|
|
//--- leading-line-comment.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-line-comment.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK4
|
|
// CHECK4: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
// My line comment
|
|
import A;
|
|
|
|
//--- leading-block-comment1.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-block-comment1.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK5
|
|
// CHECK5: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
/*My block comment */
|
|
import A;
|
|
|
|
//--- leading-block-comment2.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-block-comment2.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK6
|
|
// CHECK6: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
/*My line comment */ import A;
|
|
|
|
//--- inline-block-comment1.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-block-comment1.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK7
|
|
// CHECK7: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
export/*a comment*/module/*another comment*/A;
|
|
|
|
//--- inline-block-comment2.cpp
|
|
// RUN: %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-block-comment2.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK8
|
|
// CHECK8: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
module/*a comment*/;
|
|
|
|
//--- leading-directives.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-directives.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK9
|
|
// CHECK9: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
#define A
|
|
#undef A
|
|
#if A
|
|
#ifdef A
|
|
#elifdef A
|
|
#elifndef A
|
|
#endif
|
|
#ifndef A
|
|
#elif A
|
|
#else
|
|
#endif
|
|
#endif
|
|
#pragma once;
|
|
#include <iostream>
|
|
import m;
|
|
|
|
//--- multiline-directive.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/multiline-directive.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK10
|
|
// CHECK10: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
#define MACRO(a, \
|
|
b) \
|
|
call((a), \
|
|
(b)
|
|
import a;
|
|
|
|
//--- leading-line-splice.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-line-splice.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK11
|
|
// CHECK11: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
\
|
|
module;
|
|
|
|
//--- leading-line-splice-trailing-whitespace.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/leading-line-splice-trailing-whitespace.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK12
|
|
// CHECK12: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
// v This backslash has trailing whitespace.
|
|
\
|
|
export module A;
|
|
|
|
//--- comment-line-splice.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/comment-line-splice.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK13
|
|
// CHECK13-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
// My comment continues next-line!\
|
|
import A;
|
|
|
|
//--- comment-line-splice-trailing-whitespace.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/comment-line-splice-trailing-whitespace.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK14
|
|
// CHECK14-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
// My comment continues next-line! This backslash has trailing whitespace. -> \
|
|
module;
|
|
|
|
//--- line-splice-in-directive1.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/line-splice-in-directive1.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK15
|
|
// CHECK15: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
|
|
module\
|
|
;
|
|
|
|
//--- line-splice-in-directive2.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/line-splice-in-directive2.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK16
|
|
// CHECK16: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
|
|
export\
|
|
module\
|
|
A;
|
|
|
|
//--- no-module-usage1.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/no-module-usage1.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK17
|
|
// CHECK17-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
auto main() -> int {}
|
|
|
|
//--- no-module-usage2.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/no-module-usage2.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK18
|
|
// CHECK18-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
moduleStruct{};
|
|
|
|
//--- no-module-usage3.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/no-module-usage3.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK19
|
|
// CHECK19-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
export_struct{};
|
|
|
|
//--- no-module-usage-namespace-import.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/no-module-usage-namespace-import.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK20
|
|
// CHECK20-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
import::inner xi = {};
|
|
|
|
//--- no-module-usage-namespace-module.cpp
|
|
// RUN: %clang -std=c++23 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: %t/no-module-usage-namespace-module.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --allow-empty --check-prefix=CHECK21
|
|
// CHECK21-NOT: remark: found C++20 module usage in file '{{.*}}' [-Rmodules-driver]
|
|
module::inner yi = {};
|
|
|
|
// RUN: not %clang -std=c++20 -ccc-print-phases -fmodules-driver -Rmodules-driver \
|
|
// RUN: imaginary-file.cpp %t/empty.cpp 2>&1 \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK-NON-EXISTING-FILE-ERR
|
|
// CHECK-NON-EXISTING-FILE-ERR: clang: error: no such file or directory: 'imaginary-file.cpp'
|