Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions clang/lib/Driver/ModulesDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/DirectedGraph.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/TypeSwitch.h"
Expand Down Expand Up @@ -1528,9 +1529,12 @@ void driver::modules::runModulesDriver(
// TODO: Install all updated command-lines produced by the dependency scan.
// TODO: Fix-up command-lines for named module imports.

// TODO: Sort the graph topologically before adding jobs back to the
// Compilation being built.
for (auto *N : Graph)
if (auto *JN = dyn_cast<JobNode>(N))
C.addCommand(std::move(JN->Job));
llvm::ReversePostOrderTraversal<CompilationGraph *> TopologicallySortedNodes(
&Graph);
assert(isa<RootNode>(*TopologicallySortedNodes.begin()) &&
"First node in topological order must be the root!");
auto TopologicallySortedJobNodes = llvm::map_range(
llvm::drop_begin(TopologicallySortedNodes), llvm::CastTo<JobNode>);
for (auto *JN : TopologicallySortedJobNodes)
C.addCommand(std::move(JN->Job));
}
75 changes: 75 additions & 0 deletions clang/test/Driver/modules-driver-clang-modules-only.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Checks that -fmodules-driver correctly handles compilations using Clang modules.

// RUN: split-file %s %t
// RUN: rm -rf %t/modules-cache
// RUN: %clang -std=c++23 \
// RUN: -fmodules-driver -Rmodules-driver \
// RUN: -fmodules -Rmodule-import \
// RUN: -fmodule-map-file=%t/module.modulemap \
// RUN: -fmodules-cache-path=%t/modules-cache \
// RUN: -fsyntax-only %t/main.cpp 2>&1 \
// RUN: | sed 's:\\\\\?:/:g' \
// RUN: | FileCheck -DPREFIX=%/t %s

// The scan itself will also produce [-Rmodule-import] remarks.
// Let's skip past them, we only care about the final -cc1 commands.
// CHECK: clang: remark: printing module dependency graph [-Rmodules-driver]
// CHECK-NEXT: digraph "Module Dependency Graph" {
// CHECK: }

// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'root' from
// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'direct1' into 'root'
// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive1' into 'direct1'
// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive2' into 'direct1'
// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'direct2' into 'root'
// CHECK: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive2' into 'direct2'
Comment thread
naveen-seth marked this conversation as resolved.
Outdated

// (Because of missing include guards, this example would also run into
// redefinition errors when compiling without modules.)

/--- module.modulemap
module root { header "root.h"}
module transitive1 { header "transitive1.h" }
module transitive2 { header "transitive2.h" }
module direct1 { header "direct1.h" }
module direct2 { header "direct2.h" }

//--- root.h
#include "direct1.h"
#include "direct2.h"
int fromRoot() {
return fromDirect1() + fromDirect2();
}

//--- direct1.h
#include "transitive1.h"
#include "transitive2.h"

int fromDirect1() {
return fromTransitive1() + fromTransitive2();
}

//--- direct2.h
#include "transitive2.h"

int fromDirect2() {
return fromTransitive2() + 2;
}

//--- transitive1.h
int fromTransitive1() {
return 20;
}

//--- transitive2.h

int fromTransitive2() {
return 10;
}

//--- main.cpp
#include "root.h"

int main() {
fromRoot();
}
14 changes: 4 additions & 10 deletions clang/test/Driver/modules-driver-manifest-input-args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@
// RUN: %t/main.cpp \
// RUN: -### 2>&1 \
// RUN: | sed 's:\\\\\?:/:g' \
// RUN: | FileCheck %s -check-prefix=MAIN-CC1 -check-prefix=STDLIB-MOD-CC1 -DPREFIX=%/t
// RUN: | FileCheck %s -DPREFIX=%/t

// MAIN-CC1: "-cc1"
// MAIN-CC1-SAME: "main.cpp"
// MAIN-CC1-NOT: "-Wno-reserved-module-identifier"
// MAIN-CC1-NOT: "-internal-isystem" "[[PREFIX]]/Inputs/usr/lib/x86_64-linux-gnu/../share/libc++/v1/"

// STDLIB-MOD-CC1: "-cc1"
// STDLIB-MOD-CC1-SAME: "[[PREFIX]]/Inputs/usr/lib/x86_64-linux-gnu/../share/libc++/v1/std.cppm"
// STDLIB-MOD-CC1-SAME: "-Wno-reserved-module-identifier"
// STDLIB-MOD-CC1-SAME: "-internal-isystem" "[[PREFIX]]/Inputs/usr/lib/x86_64-linux-gnu/../share/libc++/v1/"
// CHECK: "-cc1" {{.*}} "[[PREFIX]]/Inputs/usr/lib/x86_64-linux-gnu/../share/libc++/v1/std.cppm"
// CHECK-SAME: "-Wno-reserved-module-identifier"
// CHECK-SAME: "-internal-isystem" "[[PREFIX]]/Inputs/usr/lib/x86_64-linux-gnu/../share/libc++/v1/"
Comment thread
naveen-seth marked this conversation as resolved.
Outdated

//--- main.cpp
import std;
Expand Down