Skip to content

Commit d89721c

Browse files
committed
[SYCL] Matching sizeof long double of SYCL device with that of host
static_assert of sizeof(long double)>8 fails to compile with -fsycl switch on Linux x86_64 bit target because sizeof(long double) for SYCL device is 8 bytes whereas the host is 16 bytes. This commit sets sizeof(long double) of SYCL device to match that of host
1 parent 88e56d9 commit d89721c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
20652065
Align = Target->getDoubleAlign();
20662066
break;
20672067
case BuiltinType::LongDouble:
2068-
if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
2068+
if (((getLangOpts().SYCL && getLangOpts().SYCLIsDevice) ||
2069+
(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)) &&
2070+
AuxTarget != nullptr &&
20692071
(Target->getLongDoubleWidth() != AuxTarget->getLongDoubleWidth() ||
20702072
Target->getLongDoubleAlign() != AuxTarget->getLongDoubleAlign())) {
20712073
Width = AuxTarget->getLongDoubleWidth();

clang/lib/Basic/Targets/SPIR.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32SPIRTargetInfo
209209
MicrosoftX86_32SPIRTargetInfo(const llvm::Triple &Triple,
210210
const TargetOptions &Opts)
211211
: WindowsX86_32SPIRTargetInfo(Triple, Opts) {
212-
LongDoubleWidth = LongDoubleAlign = 64;
213-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
214212
assert(DataLayout->getPointerSizeInBits() == 32);
215213
}
216214

@@ -261,8 +259,6 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64_SPIR64TargetInfo
261259
MicrosoftX86_64_SPIR64TargetInfo(const llvm::Triple &Triple,
262260
const TargetOptions &Opts)
263261
: WindowsX86_64_SPIR64TargetInfo(Triple, Opts) {
264-
LongDoubleWidth = LongDoubleAlign = 64;
265-
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
266262
assert(DataLayout->getPointerSizeInBits() == 64);
267263
}
268264

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-linux-gnu -fsyntax-only -DLONG_DOUBLE_SIZE=16 -verify %s
2+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir-unknown-unknown-sycldevice -aux-triple i386-pc-linux-gnu -fsyntax-only -DLONG_DOUBLE_SIZE=12 -verify %s
3+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-windows-sycldevice -aux-triple x86_64-pc-windows-msvc -fsyntax-only -DLONG_DOUBLE_SIZE=8 -verify %s
4+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir-unknown-windows-sycldevice -aux-triple i686-pc-windows-msvc -fsyntax-only -DLONG_DOUBLE_SIZE=8 -verify %s
5+
// expected-no-diagnostics
6+
7+
static_assert(sizeof(long double) == LONG_DOUBLE_SIZE, "wrong sizeof long double");

0 commit comments

Comments
 (0)