brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 201ce63 Raw
117 lines · c
1// This test verifies that the modules visible to the translation unit are computed in dependency scanning.2// "client" in the first scan represents the translation unit that imports an explicit submodule, 3//    that only exports one other module. 4// In the second scan, the translation unit that imports an explicit submodule, 5//    that exports an additional module. 6// Thus, the dependencies of the top level module for the submodule always differ from what is visible to the TU.7 8// RUN: rm -rf %t9// RUN: split-file %s %t10// RUN: sed -e "s|DIR|%/t|g" %t/compile-commands.json.in > %t/compile-commands.json11// RUN: clang-scan-deps -emit-visible-modules -compilation-database %t/compile-commands.json \12// RUN:   -j 1 -format experimental-full 2>&1 > %t/result-first-scan.json13// RUN: cat %t/result-first-scan.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=SINGLE14 15/// Re-run scan with different module map for direct dependency.16// RUN: mv %t/A_with_visible_export.modulemap %t/Sysroot/usr/include/A/module.modulemap17// RUN: clang-scan-deps -emit-visible-modules -compilation-database %t/compile-commands.json \18// RUN:   -j 1 -format experimental-full 2>&1 > %t/result.json19// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t --check-prefix=MULTIPLE20 21// RUN: %deps-to-rsp %t/result.json --module-name=transitive > %t/transitive.rsp22// RUN: %deps-to-rsp %t/result.json --module-name=visible > %t/visible.rsp23// RUN: %deps-to-rsp %t/result.json --module-name=invisible > %t/invisible.rsp24// RUN: %deps-to-rsp %t/result.json --module-name=A > %t/A.rsp25// RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp26 27// RUN: %clang @%t/transitive.rsp28// RUN: %clang @%t/visible.rsp29// RUN: %clang @%t/invisible.rsp30// RUN: %clang @%t/A.rsp31 32/// Verify compilation & scan agree with each other.33// RUN: not %clang @%t/tu.rsp -o %t/blah.o 2>&1 | FileCheck %s --check-prefix=COMPILE34 35// SINGLE:        "visible-clang-modules": [36// SINGLE-NEXT:     "A"37// SINGLE-NEXT:   ]38 39// MULTIPLE:        "visible-clang-modules": [40// MULTIPLE-NEXT:     "A",41// MULTIPLE-NEXT:     "visible"42// MULTIPLE-NEXT:   ]43 44// COMPILE-NOT:   'visible_t' must be declared before it is used45// COMPILE:       'transitive_t' must be declared before it is used46// COMPILE:       'invisible_t' must be declared before it is used47 48//--- compile-commands.json.in49[50{51  "directory": "DIR",52  "command": "clang -c DIR/client.c -isysroot DIR/Sysroot -IDIR/Sysroot/usr/include -fmodules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps",53  "file": "DIR/client.c"54}55]56 57//--- Sysroot/usr/include/A/module.modulemap58module A {59  explicit module visibleToTU {60    header "visibleToTU.h"61  }62  explicit module invisibleToTU {63    header "invisibleToTU.h" 64  }65}66 67//--- A_with_visible_export.modulemap68module A {69  explicit module visibleToTU {70    header "visibleToTU.h"71    export visible72  }73  explicit module invisibleToTU {74    header "invisibleToTU.h" 75  }76}77 78//--- Sysroot/usr/include/A/visibleToTU.h79#include <visible/visible.h>80typedef int A_visibleToTU;81 82//--- Sysroot/usr/include/A/invisibleToTU.h83#include <invisible/invisible.h>84typedef int A_invisibleToTU;85 86//--- Sysroot/usr/include/invisible/module.modulemap87module invisible {88  umbrella "."89}90 91//--- Sysroot/usr/include/invisible/invisible.h92typedef int invisible_t;93 94//--- Sysroot/usr/include/visible/module.modulemap95module visible {96  umbrella "."97}98 99//--- Sysroot/usr/include/visible/visible.h100#include <transitive/transitive.h>101typedef int visible_t;102 103//--- Sysroot/usr/include/transitive/module.modulemap104module transitive {105  umbrella "."106}107 108//--- Sysroot/usr/include/transitive/transitive.h109typedef int transitive_t;110 111//--- client.c112#include <A/visibleToTU.h> 113visible_t foo_v(void);114// Both decls are not visible, thus should fail to actually compile.115transitive_t foo_t(void);116invisible_t foo_i(void); 117