51 changes: 51 additions & 0 deletions clang/test/Modules/cxx20-modules-enum-odr.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-module-interface -o %t/mod1.pcm
// RUN: %clang_cc1 -std=c++20 %t/mod2.cppm -emit-module-interface -o %t/mod2.pcm
// RUN: %clang_cc1 -std=c++20 %t/test.cpp -fprebuilt-module-path=%t -verify -fsyntax-only

//--- size_t.h

extern "C" {
typedef unsigned int size_t;
}

//--- csize_t
namespace std {
using :: size_t;
}

//--- align.h
namespace std {
enum class align_val_t : size_t {};
}

//--- mod1.cppm
module;
#include "size_t.h"
#include "align.h"
export module mod1;
namespace std {
export using std::align_val_t;
}

//--- mod2.cppm
module;
#include "size_t.h"
#include "csize_t"
#include "align.h"
export module mod2;
namespace std {
export using std::align_val_t;
}

//--- test.cpp
// expected-no-diagnostics
import mod1;
import mod2;
void test() {
std::align_val_t v;
}

53 changes: 0 additions & 53 deletions clang/test/Modules/no-eager-load.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/d.cpp \
// RUN: -fprebuilt-module-path=%t
//
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/e.cppm -o %t/e.pcm
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/f.cppm -o %t/f.pcm
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/g.cpp \
// RUN: -fprebuilt-module-path=%t
//
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/h.cppm \
// RUN: -fprebuilt-module-path=%t -o %t/h.pcm
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/i.cppm \
// RUN: -fprebuilt-module-path=%t -o %t/i.pcm
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/j.cpp \
// RUN: -fprebuilt-module-path=%t
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %t/k.cpp \
// RUN: -fprebuilt-module-path=%t

//--- a.cppm
export module a;
Expand Down Expand Up @@ -53,58 +44,14 @@ void use() {
// expected-note@* {{but in 'a' found a different body}}
}

//--- foo.h
void foo() {

}

//--- bar.h
void bar();
void foo() {
bar();
}

//--- e.cppm
module;
#include "foo.h"
export module e;
export using ::foo;

//--- f.cppm
module;
#include "bar.h"
export module f;
export using ::foo;

//--- g.cpp
import e;
import f;
void use() {
foo(); // expected-error@* {{'foo' has different definitions in different modules;}}
// expected-note@* {{but in 'e.<global>' found a different body}}
}

//--- h.cppm
export module h;
export import a;
export import b;

//--- i.cppm
export module i;
export import e;
export import f;

//--- j.cpp
import h;
void use() {
foo(); // expected-error@* {{'foo' has different definitions in different modules;}}
// expected-note@* {{but in 'a' found a different body}}
}

//--- k.cpp
import i;
void use() {
foo(); // expected-error@* {{'foo' has different definitions in different modules;}}
// expected-note@* {{but in 'e.<global>' found a different body}}
}

10 changes: 10 additions & 0 deletions clang/test/Modules/polluted-operator.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
//
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/a.cppm -o %t/a.pcm
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fprebuilt-module-path=%t -emit-module-interface -o %t/b.pcm -verify
//
// Testing the behavior of `-fskip-odr-check-in-gmf`
// RUN: %clang_cc1 -std=c++20 -fskip-odr-check-in-gmf -emit-module-interface %t/a.cppm -o \
// RUN: %t/a.pcm
// RUN: %clang_cc1 -std=c++20 -fskip-odr-check-in-gmf %t/b.cppm -fprebuilt-module-path=%t \
// RUN: -emit-module-interface -DSKIP_ODR_CHECK_IN_GMF -o %t/b.pcm -verify

//--- foo.h

Expand Down Expand Up @@ -51,7 +57,11 @@ module;
export module b;
import a;

#ifdef SKIP_ODR_CHECK_IN_GMF
// expected-no-diagnostics
#else
// expected-error@* {{has different definitions in different modules; first difference is defined here found data member '_S_copy_ctor' with an initializer}}
// expected-note@* {{but in 'a.<global>' found data member '_S_copy_ctor' with a different initializer}}
// expected-error@* {{from module 'a.<global>' is not present in definition of 'variant<_Types...>' provided earlier}}
// expected-note@* {{declaration of 'swap' does not match}}
#endif
10 changes: 10 additions & 0 deletions clang/test/Modules/pr76638.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
// RUN: %clang_cc1 -std=c++20 %t/mod4.cppm -fmodule-file=mod3=%t/mod3.pcm \
// RUN: -fsyntax-only -verify

// Testing the behavior of `-fskip-odr-check-in-gmf`
// RUN: %clang_cc1 -std=c++20 %t/mod3.cppm -fskip-odr-check-in-gmf \
// RUN: -emit-module-interface -o %t/mod3.pcm
// RUN: %clang_cc1 -std=c++20 %t/mod4.cppm -fmodule-file=mod3=%t/mod3.pcm \
// RUN: -fskip-odr-check-in-gmf -DSKIP_ODR_CHECK_IN_GMF -fsyntax-only -verify

//--- size_t.h

extern "C" {
Expand Down Expand Up @@ -65,5 +71,9 @@ export module mod4;
import mod3;
export using std::align_val_t;

#ifdef SKIP_ODR_CHECK_IN_GMF
// expected-no-diagnostics
#else
// expected-error@align.h:* {{'std::align_val_t' has different definitions in different modules; defined here first difference is enum with specified type 'size_t' (aka 'int')}}
// expected-note@align.h:* {{but in 'mod3.<global>' found enum with specified type 'size_t' (aka 'unsigned int')}}
#endif
56 changes: 56 additions & 0 deletions clang/test/Modules/skip-odr-check-in-gmf.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// Baseline testing to make sure we can detect the ODR violation from the CC1 invocation.
// RUNX: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
// RUNX: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm
// RUNX: %clang_cc1 -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -verify
//
// Testing that we can ignore the ODR violation from the driver invocation.
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
// RUN: %clang -std=c++20 %t/b.cppm --precompile -o %t/b.pcm
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify \
// RUN: -DIGNORE_ODR_VIOLATION
//
// Testing that the driver can require to check the ODR violation.
// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/a.cppm --precompile -o %t/a.pcm
// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/b.cppm --precompile -o %t/b.pcm
// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/test.cc -fprebuilt-module-path=%t \
// RUN: -fsyntax-only -Xclang -verify

//--- func1.h
bool func(int x, int y) {
return true;
}

//--- func2.h
bool func(int x, int y) {
return false;
}

//--- a.cppm
module;
#include "func1.h"
export module a;
export using ::func;

//--- b.cppm
module;
#include "func2.h"
export module b;
export using ::func;

//--- test.cc
import a;
import b;
bool test() {
return func(1, 2);
}

#ifdef IGNORE_ODR_VIOLATION
// expected-no-diagnostics
#else
// expected-error@func2.h:1 {{'func' has different definitions in different modules;}}
// expected-note@func1.h:1 {{but in 'a.<global>' found a different body}}
#endif