Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++20] [Module] Support extern C/C++ semantics
According to [module.unit]p7.2.3, a declaration within a linkage-specification should be attached to the global module. This let user to forward declare types across modules. Reviewed by: rsmith, aaron.ballman Differential Revision: https://reviews.llvm.org/D110215
- Loading branch information
1 parent
ec64d10
commit e587372
Showing
19 changed files
with
211 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module; | ||
#include "h2.h" | ||
export module X; | ||
|
||
extern "C++" class CPP { | ||
public: | ||
void print() {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extern "C" void foo(); | ||
extern "C" { | ||
void bar(); | ||
int baz(); | ||
double double_func(); | ||
} | ||
|
||
extern "C++" { | ||
void bar_cpp(); | ||
int baz_cpp(); | ||
double double_func_cpp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern "C++" class CPP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern "C" struct C; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern "C++" int a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: %clang_cc1 -std=c++20 %s -verify | ||
// expected-no-diagnostics | ||
module; | ||
|
||
#include "Inputs/h1.h" | ||
|
||
export module x; | ||
|
||
extern "C" void foo() { | ||
return; | ||
} | ||
|
||
extern "C" { | ||
void bar() { | ||
return; | ||
} | ||
int baz() { | ||
return 3; | ||
} | ||
double double_func() { | ||
return 5.0; | ||
} | ||
} | ||
|
||
extern "C++" { | ||
void bar_cpp() { | ||
return; | ||
} | ||
int baz_cpp() { | ||
return 3; | ||
} | ||
double double_func_cpp() { | ||
return 5.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clang_cc1 -std=c++20 %s -verify | ||
// expected-no-diagnostics | ||
module; | ||
|
||
#include "Inputs/h2.h" | ||
|
||
export module x; | ||
|
||
extern "C++" class CPP {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This tests whether the global module would be created when the program don't declare it explicitly. | ||
// RUN: %clang_cc1 -std=c++20 %s -verify | ||
// expected-no-diagnostics | ||
export module x; | ||
|
||
extern "C" void foo(); | ||
extern "C++" class CPP {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: %clang_cc1 -std=c++20 %s -verify | ||
// expected-no-diagnostics | ||
module; | ||
|
||
#include "Inputs/h4.h" | ||
|
||
export module x; | ||
|
||
extern "C" struct C { | ||
int a; | ||
int b; | ||
double d; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clang_cc1 -std=c++20 %s -verify | ||
// expected-no-diagnostics | ||
module; | ||
|
||
#include "Inputs/h4.h" | ||
|
||
export module x; | ||
|
||
extern "C++" int a = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: rm -fr %t | ||
// RUN: mkdir %t | ||
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/CPP.cppm -I%S/Inputs -o %t/X.pcm | ||
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -verify | ||
module; | ||
#include "Inputs/h2.h" | ||
export module use; | ||
import X; | ||
void printX(CPP *cpp) { | ||
cpp->print(); // expected-error {{'CPP' must be defined before it is used}} | ||
// expected-error@-1 {{'CPP' must be defined before it is used}} | ||
// expected-error@-2 {{no member named 'print' in 'CPP'}} | ||
// expected-note@Inputs/CPP.cppm:5 {{definition here is not reachable}} | ||
// expected-note@Inputs/CPP.cppm:5 {{definition here is not reachable}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extern "C" void foo(); | ||
extern "C" { | ||
void bar(); | ||
int baz(); | ||
double double_func(); | ||
} | ||
extern "C++" class CPP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s | ||
|
||
module; | ||
|
||
#include "Inputs/module-extern-C.h" | ||
|
||
export module x; | ||
|
||
// CHECK: define dso_local void @foo() | ||
extern "C" void foo() { | ||
return; | ||
} | ||
|
||
extern "C" { | ||
// CHECK: define dso_local void @bar() | ||
void bar() { | ||
return; | ||
} | ||
// CHECK: define dso_local i32 @baz() | ||
int baz() { | ||
return 3; | ||
} | ||
// CHECK: define dso_local double @double_func() | ||
double double_func() { | ||
return 5.0; | ||
} | ||
} |