[PATCH] D142075: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 18 19:15:17 PST 2023


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, jhuber6, yaxunl, rjmccall, tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, guansong.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Fix #58087.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142075

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/OpenMP/float16_sema.cpp


Index: clang/test/OpenMP/float16_sema.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+    __fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -944,8 +944,9 @@
       // CUDA host and device may have different _Float16 support, therefore
       // allows f16 literals to avoid false alarm.
       // ToDo: more precise check for CUDA.
-      if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-          s[1] == '1' && s[2] == '6') {
+      if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+           (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+          s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
         s += 2; // success, eat up 2 characters.
         isFloat16 = true;
         continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142075.490356.patch
Type: text/x-patch
Size: 1199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230119/0777bfc1/attachment.bin>


More information about the cfe-commits mailing list