Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions clang/lib/Sema/SemaSYCLDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,16 +1540,32 @@ void SemaSYCL::addSYCLAddIRAttributesFunctionAttr(

// There could be multiple of the same attribute applied to the same
// declaration. If so, we want to merge them.
// If there are still dependent expressions in the attribute, we delay merging
// till after instantiation.
if (!hasDependentExpr(Attr->args_begin(), Attr->args_size()) &&
D->hasAttr<SYCLAddIRAttributesFunctionAttr>()) {
Attr = mergeSYCLAddIRAttributesFunctionAttr(D, *Attr);
if (D->hasAttr<SYCLAddIRAttributesFunctionAttr>()) {
// Check if any of the existing attributes have dependent expressions.
bool ExistingAttrHasDependent = false;
for (const auto *ExistingAttr :
D->specific_attrs<SYCLAddIRAttributesFunctionAttr>()) {
if (hasDependentExpr(ExistingAttr->args_begin(),
ExistingAttr->args_size())) {
ExistingAttrHasDependent = true;
break;
}
}

// If null is returned, the attribute did not change after merge and we can
// exit.
if (!Attr)
return;
// Check if the new attribute has dependent expressions.
bool NewAttrHasDependent =
hasDependentExpr(Attr->args_begin(), Attr->args_size());

// If there are still dependent expressions in either attribute, we delay
// merging till after instantiation.
if (!ExistingAttrHasDependent && !NewAttrHasDependent) {
Attr = mergeSYCLAddIRAttributesFunctionAttr(D, *Attr);

// If null is returned, the attribute did not change after merge and we
// can exit.
if (!Attr)
return;
}
}
D->addAttr(Attr);

Expand Down
58 changes: 58 additions & 0 deletions clang/test/AST/ast-attr-add-ir-attributes-merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,64 @@ void FunctionDecl3(){};
[[__sycl_detail__::add_ir_attributes_function({"Attr1", "Attr3"}, "Attr3", false)]]
void FunctionDecl4(){};

// CHECK: FunctionDecl {{.*}} TemplateDecl1 'void ()'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: SYCLAddIRAttributesFunctionAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr1"
// CHECK-NEXT: DeclRefExpr {{.*}} <col:56> 'int' NonTypeTemplateParm {{.*}} 'X' 'int'
// CHECK-NEXT: SYCLAddIRAttributesFunctionAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr2"
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
// CHECK-NEXT: value: Int 1
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
template <int X>
[[__sycl_detail__::add_ir_attributes_function("Attr1", X)]]
[[__sycl_detail__::add_ir_attributes_function("Attr2", 1)]]
void TemplateDecl1(){};

// CHECK: FunctionDecl {{.*}} TemplateDecl2 'void ()'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: SYCLAddIRAttributesFunctionAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr1"
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
// CHECK-NEXT: value: Int 1
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
// CHECK-NEXT: SYCLAddIRAttributesFunctionAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr2"
// CHECK-NEXT: DeclRefExpr {{.*}} <col:56> 'int' NonTypeTemplateParm {{.*}} 'X' 'int'
template <int X>
[[__sycl_detail__::add_ir_attributes_function("Attr1", 1)]]
[[__sycl_detail__::add_ir_attributes_function("Attr2", X)]]
void TemplateDecl2(){};

// CHECK: FunctionDecl {{.*}} TemplateDecl3 'void ()'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: SYCLAddIRAttributesFunctionAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr2"
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
// CHECK-NEXT: value: LValue
// CHECK-NEXT: StringLiteral {{.*}} 'const char[6]' lvalue "Attr1"
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
// CHECK-NEXT: value: Int 2
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2
// CHECK-NEXT: ConstantExpr {{.*}} 'int'
// CHECK-NEXT: value: Int 1
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
template <int X>
[[__sycl_detail__::add_ir_attributes_function("Attr1", 1)]]
[[__sycl_detail__::add_ir_attributes_function("Attr2", 2)]]
void TemplateDecl3(){};

// CHECK: CXXRecordDecl [[GlobalVarStructRedecl1ID1:0x[0-9a-f]+]] {{.*}} struct GlobalVarStructRedecl1
// CHECK-NEXT: SYCLAddIRAttributesGlobalVariableAttr
// CHECK-NEXT: ConstantExpr {{.*}} 'const char[6]' lvalue
Expand Down
Loading