Skip to content

Commit 289230c

Browse files
authored
[SYCL] [FPGA] Fix linking error with template parameter support for work_group_size attributes (#2975)
A linking error was introduced on PR #2906 where template declaration and definition was added in different files. This patch fixes the issue by moving the template definition for addIntelSYCLTripleArgFunctionAttr to Sema.h. Signed-off-by: Soumi Manna <soumi.manna@intel.com>
1 parent 6ea38f0 commit 289230c

File tree

2 files changed

+74
-74
lines changed

2 files changed

+74
-74
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12962,6 +12962,80 @@ void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D,
1296212962
D->addAttr(::new (Context) AttrType(Context, CI, E));
1296312963
}
1296412964

12965+
template <typename AttrInfo>
12966+
static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI,
12967+
const Expr *Expr, unsigned &Val,
12968+
unsigned Idx) {
12969+
assert(Expr && "Attribute must have an argument.");
12970+
12971+
if (!Expr->isInstantiationDependent()) {
12972+
Optional<llvm::APSInt> ArgVal =
12973+
Expr->getIntegerConstantExpr(S.getASTContext());
12974+
12975+
if (!ArgVal) {
12976+
S.Diag(AI.getLocation(), diag::err_attribute_argument_type)
12977+
<< &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
12978+
return false;
12979+
}
12980+
12981+
if (ArgVal->isNegative()) {
12982+
S.Diag(Expr->getExprLoc(),
12983+
diag::warn_attribute_requires_non_negative_integer_argument)
12984+
<< &AI << Idx << Expr->getSourceRange();
12985+
return true;
12986+
}
12987+
12988+
Val = ArgVal->getZExtValue();
12989+
if (Val == 0) {
12990+
S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero)
12991+
<< &AI << Expr->getSourceRange();
12992+
return false;
12993+
}
12994+
}
12995+
return true;
12996+
}
12997+
12998+
template <typename AttrType>
12999+
static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr,
13000+
Expr *YDimExpr, Expr *ZDimExpr,
13001+
const AttrType &Attr) {
13002+
// Accept template arguments for now as they depend on something else.
13003+
// We'll get to check them when they eventually get instantiated.
13004+
if (XDimExpr->isValueDependent() ||
13005+
(YDimExpr && YDimExpr->isValueDependent()) ||
13006+
(ZDimExpr && ZDimExpr->isValueDependent()))
13007+
return false;
13008+
13009+
unsigned XDim = 0;
13010+
if (!handleMaxWorkSizeAttrExpr(S, Attr, XDimExpr, XDim, 0))
13011+
return true;
13012+
13013+
unsigned YDim = 0;
13014+
if (YDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, YDimExpr, YDim, 1))
13015+
return true;
13016+
13017+
unsigned ZDim = 0;
13018+
if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2))
13019+
return true;
13020+
13021+
return false;
13022+
}
13023+
13024+
template <typename WorkGroupAttrType>
13025+
void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D,
13026+
const AttributeCommonInfo &CI,
13027+
Expr *XDimExpr, Expr *YDimExpr,
13028+
Expr *ZDimExpr) {
13029+
WorkGroupAttrType TmpAttr(Context, CI, XDimExpr, YDimExpr, ZDimExpr);
13030+
13031+
if (checkMaxWorkSizeAttrArguments(*this, XDimExpr, YDimExpr, ZDimExpr,
13032+
TmpAttr))
13033+
return;
13034+
13035+
D->addAttr(::new (Context)
13036+
WorkGroupAttrType(Context, CI, XDimExpr, YDimExpr, ZDimExpr));
13037+
}
13038+
1296513039
template <typename AttrType>
1296613040
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
1296713041
Expr *E) {

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,80 +3061,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL,
30613061
return Result;
30623062
}
30633063

3064-
template <typename AttrInfo>
3065-
static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI,
3066-
const Expr *Expr, unsigned &Val,
3067-
unsigned Idx) {
3068-
assert(Expr && "Attribute must have an argument.");
3069-
3070-
if (!Expr->isInstantiationDependent()) {
3071-
Optional<llvm::APSInt> ArgVal =
3072-
Expr->getIntegerConstantExpr(S.getASTContext());
3073-
3074-
if (!ArgVal) {
3075-
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
3076-
<< &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
3077-
return false;
3078-
}
3079-
3080-
if (ArgVal->isNegative()) {
3081-
S.Diag(Expr->getExprLoc(),
3082-
diag::warn_attribute_requires_non_negative_integer_argument)
3083-
<< &AI << Idx << Expr->getSourceRange();
3084-
return true;
3085-
}
3086-
3087-
Val = ArgVal->getZExtValue();
3088-
if (Val == 0) {
3089-
S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero)
3090-
<< &AI << Expr->getSourceRange();
3091-
return false;
3092-
}
3093-
}
3094-
return true;
3095-
}
3096-
3097-
template <typename AttrType>
3098-
static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr,
3099-
Expr *YDimExpr, Expr *ZDimExpr,
3100-
const AttrType &Attr) {
3101-
// Accept template arguments for now as they depend on something else.
3102-
// We'll get to check them when they eventually get instantiated.
3103-
if (XDimExpr->isValueDependent() ||
3104-
(YDimExpr && YDimExpr->isValueDependent()) ||
3105-
(ZDimExpr && ZDimExpr->isValueDependent()))
3106-
return false;
3107-
3108-
unsigned XDim = 0;
3109-
if (!handleMaxWorkSizeAttrExpr(S, Attr, XDimExpr, XDim, 0))
3110-
return true;
3111-
3112-
unsigned YDim = 0;
3113-
if (YDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, YDimExpr, YDim, 1))
3114-
return true;
3115-
3116-
unsigned ZDim = 0;
3117-
if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2))
3118-
return true;
3119-
3120-
return false;
3121-
}
3122-
3123-
template <typename WorkGroupAttrType>
3124-
void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D,
3125-
const AttributeCommonInfo &CI,
3126-
Expr *XDimExpr, Expr *YDimExpr,
3127-
Expr *ZDimExpr) {
3128-
WorkGroupAttrType TmpAttr(Context, CI, XDimExpr, YDimExpr, ZDimExpr);
3129-
3130-
if (checkMaxWorkSizeAttrArguments(*this, XDimExpr, YDimExpr, ZDimExpr,
3131-
TmpAttr))
3132-
return;
3133-
3134-
D->addAttr(::new (Context)
3135-
WorkGroupAttrType(Context, CI, XDimExpr, YDimExpr, ZDimExpr));
3136-
}
3137-
31383064
// Handles reqd_work_group_size and max_work_group_size.
31393065
template <typename WorkGroupAttr>
31403066
static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {

0 commit comments

Comments
 (0)