Skip to content

Commit

Permalink
Merge pull request triSYCL#125 from lforg37/AllowHLSAPInt
Browse files Browse the repository at this point in the history
Allow signed _ExtInt(1)
  • Loading branch information
keryell committed Oct 13, 2021
2 parents c5dc796 + 80799fa commit d281d2b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 117 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11384,7 +11384,7 @@ def warn_sycl_kernel_return_type : Warning<
InGroup<IgnoredAttributes>;

def err_ext_int_bad_size : Error<"%select{signed|unsigned}0 _ExtInt must "
"have a bit size of at least %select{2|1}0">;
"have a bit size of at least 1">;
def err_ext_int_max_size : Error<"%select{signed|unsigned}0 _ExtInt of bit "
"sizes greater than %1 not supported">;
def err_esimd_glob_cant_init : Error<
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,9 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM,
// Zero-extend bool.
if (C->getType()->isIntegerTy(1)) {
llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType);
return llvm::ConstantExpr::getZExt(C, boolTy);
if (C->getType()->getScalarSizeInBits() < boolTy->getScalarSizeInBits()) {
return llvm::ConstantExpr::getZExt(C, boolTy);
}
}

return C;
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,13 +2262,9 @@ QualType Sema::BuildExtIntType(bool IsUnsigned, Expr *BitWidth,
return QualType();

int64_t NumBits = Bits.getSExtValue();
if (!IsUnsigned && NumBits < 2) {
Diag(Loc, diag::err_ext_int_bad_size) << 0;
return QualType();
}

if (IsUnsigned && NumBits < 1) {
Diag(Loc, diag::err_ext_int_bad_size) << 1;
if (NumBits < 1) {
Diag(Loc, diag::err_ext_int_bad_size) << ((IsUnsigned) ? 1 : 0);
return QualType();
}

Expand Down
16 changes: 6 additions & 10 deletions clang/test/SemaCXX/ext-int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ _ExtInt(33) Declarations(_ExtInt(48) &Param) { // Useable in params and returns.
unsigned _ExtInt(5) e = 5;
_ExtInt(5) unsigned f;

_ExtInt(-3) g; // expected-error{{signed _ExtInt must have a bit size of at least 2}}
_ExtInt(0) h; // expected-error{{signed _ExtInt must have a bit size of at least 2}}
_ExtInt(1) i; // expected-error{{signed _ExtInt must have a bit size of at least 2}}
_ExtInt(2) j;;
_ExtInt(-3) g; // expected-error{{signed _ExtInt must have a bit size of at least 1}}
_ExtInt(0) h; // expected-error{{signed _ExtInt must have a bit size of at least 1}}
_ExtInt(1) j;;
unsigned _ExtInt(0) k;// expected-error{{unsigned _ExtInt must have a bit size of at least 1}}
unsigned _ExtInt(1) l;
signed _ExtInt(1) m; // expected-error{{signed _ExtInt must have a bit size of at least 2}}
signed _ExtInt(0) m; // expected-error{{signed _ExtInt must have a bit size of at least 1}}

constexpr _ExtInt(6) n = 33; // expected-warning{{implicit conversion from 'int' to 'const _ExtInt(6)' changes value from 33 to -31}}
constexpr _ExtInt(7) o = 33;
Expand All @@ -33,18 +32,15 @@ _ExtInt(33) Declarations(_ExtInt(48) &Param) { // Useable in params and returns.
unsigned _ExtInt(0xFFFFFFFFFF) q; // expected-error {{unsigned _ExtInt of bit sizes greater than 16777215 not supported}}

// Ensure template params are instantiated correctly.
// expected-error@5{{signed _ExtInt must have a bit size of at least 2}}
// expected-error@5{{signed _ExtInt must have a bit size of at least 1}}
// expected-error@6{{unsigned _ExtInt must have a bit size of at least 1}}
// expected-note@+1{{in instantiation of template class }}
HasExtInt<-1> r;
// expected-error@5{{signed _ExtInt must have a bit size of at least 2}}
// expected-error@5{{signed _ExtInt must have a bit size of at least 1}}
// expected-error@6{{unsigned _ExtInt must have a bit size of at least 1}}
// expected-note@+1{{in instantiation of template class }}
HasExtInt<0> s;
// expected-error@5{{signed _ExtInt must have a bit size of at least 2}}
// expected-note@+1{{in instantiation of template class }}
HasExtInt<1> t;
HasExtInt<2> u;

_ExtInt(-3.0) v; // expected-error {{integral constant expression must have integral or unscoped enumeration type, not 'double'}}
_ExtInt(3.0) x; // expected-error {{integral constant expression must have integral or unscoped enumeration type, not 'double'}}
Expand Down
Loading

0 comments on commit d281d2b

Please sign in to comment.