[clang] [HLSL] Implement floating literal suffixes (PR #87270)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 11:54:54 PDT 2024


================
@@ -4117,14 +4117,17 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
   } else if (Literal.isFloatingLiteral()) {
     QualType Ty;
     if (Literal.isHalf){
-      if (getOpenCLOptions().isAvailableOption("cl_khr_fp16", getLangOpts()))
+      if (getLangOpts().HLSL ||
+          getOpenCLOptions().isAvailableOption("cl_khr_fp16", getLangOpts()))
         Ty = Context.HalfTy;
       else {
         Diag(Tok.getLocation(), diag::err_half_const_requires_fp16);
         return ExprError();
       }
     } else if (Literal.isFloat)
       Ty = Context.FloatTy;
+    else if (getLangOpts().HLSL && Literal.isLong)
+      Ty = Context.DoubleTy;
     else if (Literal.isLong)
       Ty = Context.LongDoubleTy;
----------------
bogner wrote:

Probably better to put the HLSL check under the existing `Literal.isLong` check. This better matches the style of the rest of the function and will probably be less error-prone if something changes here in the future.

https://github.com/llvm/llvm-project/pull/87270


More information about the cfe-commits mailing list