brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 303879f Raw
121 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4//5// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s6// RUN: %clang_cc1 -DDEFINE_LOCALLY -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.modulemap %t/use.cpp -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s7 8//--- module.modulemap9module a { header "a.h" export * }10module b { header "b.h" export * }11module c { header "c.h" export * }12 13//--- nonmodular.h14void not_constant();15 16template<typename T> struct A {17  template<T M> static inline T N = [] { not_constant(); return M; } ();18};19 20template<typename T, T M> inline T N = [] { not_constant(); return M; } ();21 22template<typename T, T M> inline auto L = [] {};23 24template<typename T> int Z;25 26// These lambdas should not be merged, despite having the same context decl and27// mangling number (but different signatures).28inline auto MultipleLambdas = ((void)[](int*) { return 1; }, [] { return 2; });29 30//--- a.h31#include "nonmodular.h"32 33//--- b.h34#include "a.h"35 36int b1() { return A<int>::N<1>; }37int b2() { return N<int, 1>; }38 39inline auto x1 = L<int, 1>;40inline auto x2 = L<int, 2>;41 42inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>;43inline constexpr int *xP = P;44 45static_assert(!__is_same(decltype(x1), decltype(x2)));46 47//--- c.h48#include "a.h"49 50int c1() { return A<int>::N<2>; }51int c2() { return N<int, 2>; }52 53inline auto y2 = L<int, 2>;54inline auto y1 = L<int, 1>;55 56inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>;57inline constexpr int *yP = P;58 59//--- use.cpp60#ifdef DEFINE_LOCALLY61#include "nonmodular.h"62 63inline constexpr int *P = &Z<decltype([] { static int n; return &n; }())>;64inline constexpr int *zP = P;65 66auto z0 = L<int, 0>;67auto z2 = L<int, 2>;68auto z1 = L<int, 1>;69#endif70 71#include "b.h"72#include "c.h"73 74int b1v = b1();75int b2v = b2();76int c1v = c1();77int c2v = c2();78 79// We should merge together matching lambdas.80static_assert(__is_same(decltype(x1), decltype(y1)));81static_assert(__is_same(decltype(x2), decltype(y2)));82static_assert(!__is_same(decltype(x1), decltype(x2)));83static_assert(!__is_same(decltype(y1), decltype(y2)));84static_assert(!__is_same(decltype(x1), decltype(y2)));85static_assert(!__is_same(decltype(x2), decltype(y1)));86static_assert(xP == yP);87#ifdef DEFINE_LOCALLY88static_assert(!__is_same(decltype(x1), decltype(z0)));89static_assert(!__is_same(decltype(x2), decltype(z0)));90static_assert(__is_same(decltype(x1), decltype(z1)));91static_assert(__is_same(decltype(x2), decltype(z2)));92static_assert(xP == zP);93#endif94 95static_assert(MultipleLambdas() == 2);96 97// We should not merge the instantiated lambdas from `b.h` and `c.h` together,98// even though they will both have anonymous declaration number #1 within99// A<int> and within the TU, respectively.100 101// CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_Z1NIiLi1EE) {102// CHECK: load i8, ptr @_ZGV1NIiLi1EE, align 8103// CHECK: call {{.*}} i32 @_ZNK1NIiLi1EEMUlvE_clEv(104// CHECK: store i32 {{.*}}, ptr @_Z1NIiLi1EE105 106// CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN1AIiE1NILi1EEE) {107// CHECK: load i8, ptr @_ZGVN1AIiE1NILi1EEE, align 8108// CHECK: call {{.*}} i32 @_ZNK1AIiE1NILi1EEMUlvE_clEv(109// CHECK: store i32 {{.*}}, ptr @_ZN1AIiE1NILi1EEE110 111// CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_Z1NIiLi2EE) {112// CHECK: load i8, ptr @_ZGV1NIiLi2EE, align 8113// CHECK: call {{.*}} i32 @_ZNK1NIiLi2EEMUlvE_clEv(114// CHECK: store i32 {{.*}}, ptr @_Z1NIiLi2EE115 116// CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN1AIiE1NILi2EEE) {117// CHECK: load i8, ptr @_ZGVN1AIiE1NILi2EEE, align 8118// CHECK: call {{.*}} i32 @_ZNK1AIiE1NILi2EEMUlvE_clEv(119// CHECK: store i32 {{.*}}, ptr @_ZN1AIiE1NILi2EEE120 121