-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Implement export
keyword
#96823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -x hlsl -ast-dump -o - %s | FileCheck %s | ||
|
||
// CHECK:ExportDecl 0x{{[0-9a-f]+}} <{{.*}}> col:1 | ||
// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> col:13 used f1 'void ()' | ||
// CHECK:CompoundStmt 0x{{[0-9a-f]+}} <{{.*}}> | ||
export void f1() {} | ||
|
||
// CHECK:NamespaceDecl 0x{{[0-9a-f]+}} <{{.*}}> | ||
// CHECK:ExportDecl 0x{{[0-9a-f]+}} <{{.*}}> col:3 | ||
// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> col:15 used f2 'void ()' | ||
// CHECK:CompoundStmt 0x{{[0-9a-f]+}} <{{.*}}> | ||
namespace MyNamespace { | ||
export void f2() {} | ||
} | ||
|
||
// CHECK:ExportDecl 0x{{[0-9a-f]+}} <{{.*}}> | ||
// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> col:10 used f3 'void ()' | ||
// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> col:10 used f4 'void ()' | ||
// CHECK:CompoundStmt 0x{{[0-9a-f]+}} <{{.*}}> | ||
export { | ||
void f3() {} | ||
void f4() {} | ||
} |
This file contains hidden or 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,20 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
||
// CHECK: define void @"?f1@@YAXXZ"() | ||
export void f1() { | ||
} | ||
|
||
// CHECK: define void @"?f2@MyNamespace@@YAXXZ"() | ||
namespace MyNamespace { | ||
export void f2() { | ||
} | ||
} | ||
|
||
export { | ||
// CHECK: define void @"?f3@@YAXXZ"() | ||
// CHECK: define void @"?f4@@YAXXZ"() | ||
void f3() {} | ||
void f4() {} | ||
} |
This file contains hidden or 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,56 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s -verify | ||
|
||
export void f1(); | ||
|
||
export void f1() {} | ||
|
||
namespace { // expected-note {{anonymous namespace begins here}} | ||
export void f2(); // expected-error {{export declaration appears within anonymous namespace}} | ||
} | ||
|
||
export void f3(); | ||
|
||
export { // expected-note {{export block begins here}} | ||
void f4() {} | ||
export void f5() {} // expected-error {{export declaration appears within another export declaration}} | ||
int A; // expected-error {{export declaration can only be used on functions}} | ||
namespace ns { // expected-error {{export declaration can only be used on functions}} | ||
void f6(); | ||
} | ||
} | ||
|
||
export { // expected-note {{export block begins here}} | ||
export { // expected-error {{export declaration appears within another export declaration}} | ||
void f(); | ||
} | ||
} | ||
|
||
void export f7() {} // expected-error {{expected unqualified-id}} | ||
|
||
export static void f8() {} // expected-error {{declaration of 'f8' with internal linkage cannot be exported}} | ||
|
||
export void f9(); // expected-note {{previous declaration is here}} | ||
static void f9(); // expected-error {{static declaration of 'f9' follows non-static declaration}} | ||
|
||
static void f10(); // expected-note {{previous declaration is here}} | ||
export void f10(); // expected-error {{cannot export redeclaration 'f10' here since the previous declaration has internal linkage}} | ||
|
||
export float V1; // expected-error {{export declaration can only be used on functions}} | ||
|
||
static export float V2; // expected-error{{expected unqualified-id}} | ||
|
||
export static float V3 = 0; // expected-error {{export declaration can only be used on functions}} | ||
|
||
export groupshared float V4; // expected-error {{export declaration can only be used on functions}} | ||
|
||
void f6() { | ||
export int i; // expected-error {{expected expression}} | ||
} | ||
|
||
export cbuffer CB { // expected-error {{export declaration can only be used on functions}} | ||
int a; | ||
} | ||
|
||
export template<typename T> void tf1(T t) {} // expected-error {{export declaration can only be used on functions}} | ||
|
||
void f5() export {} // expected-error {{expected function body after function declarator}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for prohibiting nested exports?
I notice that C++ allows nested
extern 'C'
s, for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each export creates a new ExportDecl node in the AST three and limiting it to just one make it cleaner. I am not aware of any specific reason other than maybe this and to keep the syntax and parsing code identical to C++ modules export.