brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 8546b33 Raw
106 lines · cpp
1// Test macro preservation in C++20 Header Units.2 3// RUN: rm -rf %t4// RUN: mkdir -p %t5// RUN: split-file %s %t6// RUN: cd %t7 8// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \9// RUN: -o hu-01.pcm10 11// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \12// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t13 14// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \15// RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm  -Rmodule-import 2>&1 | \16// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t17 18// RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \19// RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t20 21// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-01.cpp \22// RUN:  -fmodule-file=hu-02.pcm -o B.pcm -verify23 24// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-02.cpp \25// RUN:  -fmodule-file=hu-02.pcm -o C.pcm -Rmodule-import 2>&1 | \26// RUN:  FileCheck --check-prefix=CHECK-IMP-HU2 %s -DTDIR=%t27 28//--- hu-01.h29#ifndef __GUARD30#define __GUARD31 32int baz(int);33#define FORTYTWO 4234 35#define SHOULD_NOT_BE_DEFINED -136#undef SHOULD_NOT_BE_DEFINED37 38#endif // __GUARD39// expected-no-diagnostics40 41// CHECK-HU:  ====== C++20 Module structure ======42// CHECK-HU-NEXT:  Header Unit '.{{/|\\\\?}}hu-01.h' is the Primary Module at index #143 44//--- hu-02.h45export import "hu-01.h"; // expected-warning {{the implementation of header units is in an experimental phase}}46#if !defined(FORTYTWO) || FORTYTWO != 4247#error FORTYTWO missing in hu-0248#endif49 50#ifndef __GUARD51#error __GUARD missing in hu-0252#endif53 54#ifdef SHOULD_NOT_BE_DEFINED55#error SHOULD_NOT_BE_DEFINED is visible56#endif57 58#define KAP 617459 60#ifdef FOO61#define FOO_BRANCH(X) (X) + 162inline int foo(int x) {63  if (x == FORTYTWO)64    return FOO_BRANCH(x);65  return FORTYTWO;66}67#else68#define BAR_BRANCH(X) (X) + 269inline int bar(int x) {70  if (x == FORTYTWO)71    return BAR_BRANCH(x);72  return FORTYTWO;73}74#endif75 76// CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm'77// CHECK-HU2:  ====== C++20 Module structure ======78// CHECK-HU2-NEXT:  Header Unit '.{{/|\\\\?}}hu-02.h' is the Primary Module at index #279// CHECK-HU2-NEXT:   Exports:80// CHECK-HU2-NEXT:    Header Unit '.{{/|\\\\?}}hu-01.h' is at index #181// expected-no-diagnostics82 83//--- importer-01.cpp84export module B;85import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}86 87int success(int x) {88  return foo(FORTYTWO + x + KAP);89}90 91int fail(int x) {92  return bar(FORTYTWO + x + KAP); // expected-error {{use of undeclared identifier 'bar'}}93  // expected-note@* {{'baz' declared here}}94}95 96//--- importer-02.cpp97export module C;98import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}99 100int success(int x) {101  return foo(FORTYTWO + x + KAP);102}103 104// CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-02.h' from 'hu-02.pcm'105// CHECK-IMP-HU2: remark: importing module '.{{/|\\\\?}}hu-01.h' into '.{{/|\\\\?}}hu-02.h' from '[[TDIR]]{{[/\\]}}hu-01.pcm'106