-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[clang][SYCL] Add sycl_external attribute and restrict emitting device code #140282
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
base: main
Are you sure you want to change the base?
Changes from all commits
abdbf89
f631d7a
128ab1b
118656c
7c592a4
90ead01
195a3cc
a0071d1
d20382c
65262ba
770c65e
328d242
aab6f7d
385ea37
be80436
060b24f
625cff2
a9fe3fb
4eb05b8
ab845a2
3ff689e
a177b9b
58ffb64
7893e90
7e76afd
e8d26a2
82fa98a
e4d15eb
b38e578
1d82fc1
d751b43
2b22ed2
1b3a198
568b569
0ab9ac5
19d1660
a70e2df
45f7b09
4db4101
931fd76
e34f2a6
13a68d5
2c6cf7f
394fc32
96fcd60
8e42487
1981b57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4092,6 +4092,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S, | |
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/; | ||
} | ||
|
||
// SYCL 2020 section 5.10.1, "SYCL functions and member functions linkage": | ||
// When a function is declared with SYCL_EXTERNAL, that macro must be | ||
// used on the first declaration of that function in the translation unit. | ||
// Redeclarations of the function in the same translation unit may | ||
// optionally use SYCL_EXTERNAL, but this is not required. | ||
const SYCLExternalAttr *SEA = New->getAttr<SYCLExternalAttr>(); | ||
if (SEA && !Old->hasAttr<SYCLExternalAttr>()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the rest of our attributes, I'd probably suggest we support adding it up until definition. We can then do a conformance warning instead of error, but still let it work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might be reasonable. I think we might still have to make it an error if there was an ODR-use before the definition though. I'd have to think about that more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tahonermann - do you have any additional thoughts here? |
||
Diag(SEA->getLocation(), diag::err_attribute_missing_on_first_decl) | ||
<< SEA; | ||
Diag(Old->getLocation(), diag::note_previous_declaration); | ||
New->dropAttr<SYCLExternalAttr>(); | ||
} | ||
|
||
// (C++98 8.3.5p3): | ||
// All declarations for a function shall agree exactly in both the | ||
// return type and the parameter-type-list. | ||
|
@@ -12259,6 +12272,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, | |
if (NewFD->hasAttr<SYCLKernelEntryPointAttr>()) | ||
SYCL().CheckSYCLEntryPointFunctionDecl(NewFD); | ||
|
||
if (NewFD->hasAttr<SYCLExternalAttr>()) | ||
SYCL().CheckSYCLExternalFunctionDecl(NewFD); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... this seems like it should be handled when doing the attribute 'visiting', why is it here instead of there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The checks include checking for linkage which I don't think is necessarily computed at the time the attribute is visited. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you confirm that linkage isn't computed at that point? I would expect us to (since the entire declaration is read before we handle attributes) have it there, so it is a little surprising. Also, I didn't see instantiation of this attribute, do we prevent it on function templates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linkage, or rather, external visibility, which is what we actually check, can depend on other attributes like The attribute is allowed on function templates and is automatically inherited by (implicit and explicit) instantiations (and explicit specializations which is incorrect according to the C++ standard). I don't think there is anything to do to handle instantiation. We do have a testing gap to address yet though. We have good tests for diagnostics, but are missing a test to validate which symbols are actually emitted. We'll ensure that test exercises function templates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I see, the visibility attribute makes sense here, thank you for looking into that.
We've had to do some work in the past for attribute instantiation, though simple ones might be automatic. Can you make sure that specializations/partial specializations are properly tested? And diagnose if linkage isn't right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll add tests to make sure the attribute has the proper affect with regard to actually emitting symbols. Tests for diagnostics are already in place in Though, hmm, I think we're missing a test for implicit instantiation; I don't think we should diagnose cases like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This case is being diagnosed at present. Will fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To test for implicit instantiation, call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suggested change to avoid diagnosing the abovementioned case affects cases even with explicit template specializations, such as the two preceding it in the test file. Using the canonical decls doesn't solve the problem. Further investigation is needed. I will leave the FIXME as it is for this case for follow up in a subsequent PR. |
||
|
||
// Semantic checking for this function declaration (in isolation). | ||
|
||
if (getLangOpts().CPlusPlus) { | ||
|
@@ -12447,6 +12463,12 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { | |
return; | ||
} | ||
|
||
if (FD->hasAttr<SYCLExternalAttr>()) { | ||
Diag(FD->getLocation(), diag::err_sycl_attribute_invalid_main); | ||
FD->setInvalidDecl(); | ||
return; | ||
} | ||
|
||
// Functions named main in hlsl are default entries, but don't have specific | ||
// signatures they are required to conform to. | ||
if (getLangOpts().HLSL) | ||
|
@@ -16283,6 +16305,13 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, | |
} | ||
} | ||
|
||
if (FD && !FD->isInvalidDecl() && FD->hasAttr<SYCLExternalAttr>()) { | ||
SYCLExternalAttr *SEAttr = FD->getAttr<SYCLExternalAttr>(); | ||
if (FD->isDeletedAsWritten()) | ||
erichkeane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Diag(SEAttr->getLocation(), | ||
diag::err_sycl_attribute_invalid_deleted_function); | ||
} | ||
|
||
{ | ||
// Do not call PopExpressionEvaluationContext() if it is a lambda because | ||
// one is already popped when finishing the lambda in BuildLambdaExpr(). | ||
|
Uh oh!
There was an error while loading. Please reload this page.