Skip to content

Commit c10ee53

Browse files
authored
[SYCL] Issue deferred diagnostic for incorrect asm register usage (#10782)
The device compiler previously issued an asm diagnostic for the usage of a register that was incorrect for the device, even though such usage was not on the device. Now fixed by converting the diagnostic to a deferred one.
1 parent d9d5a7d commit c10ee53

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8106,8 +8106,14 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81068106
case SC_Register:
81078107
// Local Named register
81088108
if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
8109-
DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
8110-
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
8109+
DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
8110+
if (getLangOpts().SYCLIsDevice)
8111+
SYCLDiagIfDeviceCode(E->getExprLoc(),
8112+
diag::err_asm_unknown_register_name)
8113+
<< Label;
8114+
else
8115+
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
8116+
}
81118117
break;
81128118
case SC_Static:
81138119
case SC_Extern:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64 -sycl-std=2020 %s -verify
2+
3+
// This test checks that the device compiler does not issue an asm
4+
// diagnostic about a register incorrect for it, unless it is a routine
5+
// called on the device.
6+
#include "sycl.hpp"
7+
8+
void non_device_func(int value) {
9+
// expected-no-diagnostic@+1
10+
{ register int v asm ("eax") = value; }
11+
}
12+
13+
void device_func(int value) {
14+
// expected-error@+1 {{unknown register name 'eax' in asm}}
15+
{ register int v asm ("eax") = value; }
16+
}
17+
18+
int main() {
19+
sycl::queue q;
20+
21+
q.submit([&](sycl::handler &h) {
22+
// expected-note@#KernelSingleTaskKernelFuncCall {{called by 'kernel_single_task<kernel_wrapper}}
23+
h.single_task<class kernel_wrapper>(
24+
[=]() {
25+
// expected-note@+1 {{called by 'operator()'}}
26+
device_func(5);
27+
});
28+
});
29+
}

0 commit comments

Comments
 (0)