Skip to content
Merged
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
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4700,7 +4700,8 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,

if (NewElemTy.isNull()) {
// Only emit diagnostic on host for 128-bit mode attribute
if (!(DestWidth == 128 && getLangOpts().CUDAIsDevice))
if (!(DestWidth == 128 &&
(getLangOpts().CUDAIsDevice || getLangOpts().SYCLIsDevice)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side-note CUDAIsDevice || SYCLIsDevice seems like a pretty common pattern and I believe HIP also uses CUDAIsDevice, it could be good to refactor in the future this to have a common "device compilation" option if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that note: I think the same problem can be reproduced by OpenMP offload as well, so we might need to extend the condition with || (getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to reproduce this with OpenMP and open a follow up PR if it has the same issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure exactly how it works for OpenMP, but it doesn't seem to be affected, with a float128.cpp file just containing:

typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

And testing without this patch:

With SYCL:

$ ./bin/clang++ float128.cpp -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xclang -fsycl-is-device -fsyntax-only -o o
float128.cpp:1:52: error: unsupported machine mode '__TC__'
   1 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
     |                                                    ^
1 error generated.
$

With OpenMP:

$ ./bin/clang++ ../build/float128.cpp -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xclang -fopenmp-is-target-device -fsyntax-only -o o
$

And same thing without specifying an OpenMP target.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I'd like to understand how OpenMP compiler solves that problem and why OpenMP solution seems to be different from CUDA. @npmiller, do you know any reason why they should be different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I'm not very familiar with this part of the compiler, and even less with OpenMP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, now that OpenMP has SPIRV support, this popped up on my machine.

llvm-project/build main ✗ cat test.cpp
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));

llvm-project/build main ❯ ./bin/clang++ test.cpp -fopenmp -fopenmp-targets=spirv64 -Xclang -fopenmp-is-target-device -fsyntax-only -o o  --libomptarget-spirv-bc-path=./lib/spirv64-intel/
In file included from <built-in>:1:
In file included from /home/jdoerfert/dev/llvm-project/build/lib/clang/23/include/openmp_wrappers/__clang_openmp_device_functions.h:67:
In file included from /usr/lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/cstdlib:83:
In file included from /home/jdoerfert/dev/llvm-project/build/lib/clang/23/include/llvm_libc_wrappers/stdlib.h:16:
In file included from /usr/include/stdlib.h:56:
/usr/include/bits/floatn.h:83:52: error: unsupported machine mode '__TC__'
   83 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
      |                                                    ^
test.cpp:1:52: error: unsupported machine mode '__TC__'
    1 | typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
      |                                                    ^
2 errors generated.

The suggested fix works for me. Could you make a PR?

Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
return;
}
Expand Down
1 change: 1 addition & 0 deletions clang/test/SemaSYCL/float128.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify -fsyntax-only %s
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsycl-is-device -fsyntax-only %s

typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
typedef __float128 BIGTY;

template <class T>
Expand Down