Skip to content

Commit 84e458e

Browse files
committed
Handle another case of conflicting attributes for redeclarations
- throw error when same attributes with different parameters are applied - add test case
1 parent be9635e commit 84e458e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,21 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
32913291
}
32923292
}
32933293

3294+
if (New->hasAttr<ReqdWorkGroupSizeAttr>() &&
3295+
Old->hasAttr<ReqdWorkGroupSizeAttr>()) {
3296+
auto *NewDeclAttr = New->getAttr<ReqdWorkGroupSizeAttr>();
3297+
auto *OldDeclAttr = Old->getAttr<ReqdWorkGroupSizeAttr>();
3298+
if ((NewDeclAttr->getXDim() != OldDeclAttr->getXDim()) ||
3299+
(NewDeclAttr->getYDim() != OldDeclAttr->getYDim()) ||
3300+
(NewDeclAttr->getZDim() != OldDeclAttr->getZDim())) {
3301+
Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes)
3302+
<< OldDeclAttr << NewDeclAttr;
3303+
Diag(New->getLocation(), diag::warn_duplicate_attribute) << OldDeclAttr;
3304+
Diag(OldDeclAttr->getLocation(), diag::note_conflicting_attribute);
3305+
Diag(NewDeclAttr->getLocation(), diag::note_conflicting_attribute);
3306+
}
3307+
}
3308+
32943309
if (New->hasAttr<InternalLinkageAttr>() &&
32953310
!Old->hasAttr<InternalLinkageAttr>()) {
32963311
Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)

clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -triple spir64 | FileCheck %s
44

55
#ifndef TRIGGER_ERROR
6+
//first case - good case
67
[[intelfpga::no_global_work_offset]] // expected-no-diagnostics
78
void
89
func1();
@@ -12,13 +13,24 @@ func1();
1213
[[cl::reqd_work_group_size(2, 2, 2)]] void func1() {}
1314

1415
#else
15-
[[intelfpga::max_work_group_size(4, 4, 4)]] // expected-note {{conflicting attribute is here}}
16-
void
16+
//second case - expect error
17+
[[intelfpga::max_work_group_size(4, 4, 4)]] void
1718
func2();
1819

1920
[[cl::reqd_work_group_size(8, 8, 8)]] // expected-note {{conflicting attribute is here}}
2021
void
2122
func2() {}
23+
24+
//third case - expect error
25+
[[cl::reqd_work_group_size(4, 4, 4)]] // expected-note {{conflicting attribute is here}}
26+
void
27+
func3();
28+
29+
[[cl::reqd_work_group_size(1, 1, 1)]] // expected-note 2 {{conflicting attribute is here}}
30+
void
31+
// expected-warning@+1 {{attribute 'reqd_work_group_size' is already applied with different parameters}}
32+
func3() {} // expected-error {{'reqd_work_group_size' attribute conflicts with ''reqd_work_group_size'' attribute}}
33+
2234
#endif
2335

2436
template <typename Name, typename Type>
@@ -28,6 +40,7 @@ template <typename Name, typename Type>
2840
func1();
2941
#else
3042
func2();
43+
func3();
3144
#endif
3245
}
3346

0 commit comments

Comments
 (0)