Skip to content

Commit 0a3a324

Browse files
authored
[SYCL] IsDerivedFromInclusive expects a compelete type in the presence of attribute add_ir_attributes_global_variable. (#15897)
This test is crashing the compiler. `struct A {` `protected:` `static constexpr const char *ir_attribute_name = "";` `static constexpr auto ir_attribute_value = nullptr;` `};` `template <typename Ts>` `struct [[__sycl_detail__::add_ir_attributes_global_variable(` ` Ts::ir_attribute_name, Ts::ir_attribute_value)]] B {` `};` `B<A> v;` When a class attribute accepts an arbitrary expression, the underlying class needs to be a complete type.
1 parent 29f26fe commit 0a3a324

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/Sema/SemaAccess.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ static AccessResult IsDerivedFromInclusive(const CXXRecordDecl *Derived,
301301
const CXXRecordDecl *Target) {
302302
assert(Derived->getCanonicalDecl() == Derived);
303303
assert(Target->getCanonicalDecl() == Target);
304+
assert(Derived->getDefinition() && "Expecting a complete type");
304305

305306
if (Derived == Target) return AR_accessible;
306307

@@ -776,6 +777,8 @@ static AccessResult HasAccess(Sema &S,
776777
// [B3] and [M3]
777778
} else {
778779
assert(Access == AS_protected);
780+
if (!ECRecord->getDefinition())
781+
continue;
779782
switch (IsDerivedFromInclusive(ECRecord, NamingClass)) {
780783
case AR_accessible: break;
781784
case AR_inaccessible: continue;

clang/test/SemaSYCL/attr-add-ir-attributes.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,3 +991,16 @@ struct __attribute__((sycl_special_class)) InvalidSpecialClassStruct32 {
991991
struct [[__sycl_detail__::add_ir_attributes_kernel_parameter("Attr1", 1)]] InvalidKernelParameterSubjectStruct; // expected-error {{'add_ir_attributes_kernel_parameter' attribute only applies to parameters}}
992992
[[__sycl_detail__::add_ir_attributes_kernel_parameter("Attr1", 1)]] void InvalidKernelParameterSubjectFunction() {} // expected-error {{'add_ir_attributes_kernel_parameter' attribute only applies to parameters}}
993993
[[__sycl_detail__::add_ir_attributes_kernel_parameter("Attr1", 1)]] int InvalidKernelParameterSubjectVar; // expected-error {{'add_ir_attributes_kernel_parameter' attribute only applies to parameters}}
994+
995+
struct A {
996+
protected:
997+
static constexpr const char *ir_attribute_name = ""; // expected-note {{declared protected here}}
998+
static constexpr auto ir_attribute_value = nullptr; // expected-note {{declared protected here}}
999+
};
1000+
1001+
template <typename Ts>
1002+
struct [[__sycl_detail__::add_ir_attributes_global_variable(
1003+
Ts::ir_attribute_name, Ts::ir_attribute_value)]] B { // expected-error {{'ir_attribute_name' is a protected member of 'A'}} // expected-error {{'ir_attribute_value' is a protected member of 'A'}}
1004+
};
1005+
1006+
B<A> v; // expected-note {{in instantiation of template class 'B<A>' requested here}}

0 commit comments

Comments
 (0)