llvm-project/clang/test/ClangScanDeps/modules-context-hash-warnings.c
Ben Langmuir 83902c4036 Reapply "[clang][deps] Split translation units into individual -cc1 or other commands"
Attempt to fix the test failures observed in CI:
* Add Option dependency, which caused BUILD_SHARED_LIBS builds to fail
* Adapt tests that accidentally depended on the host platform: platforms
  that don't use an integrated assembler (e.g. AIX) get a different set
  of commands from the driver. Most dependency scanner tests can use
  -fsyntax-only or -E instead of -c to avoid this, and in the rare case
  we want to check -c specifically, set an explicit target so the
  behaviour is independent of the host.

Original commit message follows.

---

Instead of trying to "fix" the original driver invocation by appending
arguments to it, split it into multiple commands, and for each -cc1
command use a CompilerInvocation to give precise control over the
invocation.

This change should make it easier to (in the future) canonicalize the
command-line (e.g. to improve hits in something like ccache), apply
optimizations, or start supporting multi-arch builds, which would
require different modules for each arch.

In the long run it may make sense to treat the TU commands as a
dependency graph, each with their own dependencies on modules or earlier
TU commands, but for now they are simply a list that is executed in
order, and the dependencies are simply duplicated. Since we currently
only support single-arch builds, there is no parallelism available in
the execution.

Differential Revision: https://reviews.llvm.org/D132405
2022-08-31 09:45:11 -07:00

78 lines
2.2 KiB
C

// Differences in -W warning options should result in different canonical module
// build commands.
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
// RUN: -format experimental-full > %t/deps.json
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
// CHECK: {
// CHECK-NEXT: "modules": [
// CHECK: {
// CHECK: "command-line": [
// CHECK: "-Wall"
// CHECK: ]
// CHECK: "context-hash": "[[HASH1:.*]]"
// CHECK: "name": "Mod"
// CHECK-NEXT: }
// CHECK-NEXT: {
// CHECK: "command-line": [
// CHECK-NOT: "-Wall"
// CHECK: ]
// CHECK: "context-hash": "[[HASH2:.*]]"
// CHECK: "name": "Mod"
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: "translation-units": [
// CHECK-NEXT: {
// CHECK: "clang-module-deps": [
// CHECK-NEXT: {
// CHECK-NEXT: "context-hash": "[[HASH1]]"
// CHECK-NEXT: "module-name": "Mod"
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: "command-line": [
// CHECK: "-Wall"
// CHECK: ]
// CHECK: "input-file": "{{.*}}tu1.c"
// CHECK-NEXT: }
// CHECK: {
// CHECK: "clang-module-deps": [
// CHECK-NEXT: {
// CHECK-NEXT: "context-hash": "[[HASH2]]"
// CHECK-NEXT: "module-name": "Mod"
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: "command-line": [
// CHECK-NOT: "-Wall"
// CHECK: ]
// CHECK: "input-file": "{{.*}}tu2.c"
//--- cdb.json.template
[
{
"directory": "DIR",
"command": "clang -Wall -fsyntax-only DIR/tu1.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
"file": "DIR/tu1.c"
},
{
"directory": "DIR",
"command": "clang -fsyntax-only DIR/tu2.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
"file": "DIR/tu2.c"
},
]
//--- module.modulemap
module Mod { header "Mod.h" }
//--- Mod.h
//--- tu1.c
#include "Mod.h"
//--- tu2.c
#include "Mod.h"