[clang] [clang][Sema] Do lvalue-to-rvalue conversion on isfpclass Mask arg (PR #216929)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 18 02:05:51 PDT 2026


https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/216929

>From 6c7646b2649b4e705e9068dcdbbf38ef99d112ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 18 Aug 2026 08:54:16 +0200
Subject: [PATCH] [clang][Sema] Do lvalue-to-rvalue conversion on isfpclass
 Mask arg

Fixes #https://github.com/llvm/llvm-project/issues/216294
---
 clang/lib/Sema/SemaChecking.cpp               |  8 +++++++-
 clang/test/AST/ByteCode/builtin-functions.cpp | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3e6266b8ac542..d0190364bb209 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6481,9 +6481,15 @@ bool Sema::BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
 
   // __builtin_isfpclass has integer parameter that specify test mask. It is
   // passed in (...), so it should be analyzed completely here.
-  if (IsFPClass)
+  if (IsFPClass) {
     if (BuiltinConstantArgRange(TheCall, 1, 0, llvm::fcAllFlags))
       return true;
+    ExprResult MaskRes =
+        DefaultFunctionArrayLvalueConversion(TheCall->getArg(NumArgs - 1));
+    if (!MaskRes.isUsable())
+      return true;
+    TheCall->setArg(NumArgs - 1, MaskRes.get());
+  }
 
   // TODO: enable this code to all classification functions.
   if (IsFPClass) {
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 87ffb1cc5b609..c6a1a4f38a803 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -339,6 +339,17 @@ namespace isfpclass {
   char isfpclass_snan_1   [!__builtin_isfpclass(__builtin_nans(""), 0x0002) ? 1 : -1]; // fcQNan
   char isfpclass_snan_2   [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 1 : -1]; // ~fcFinite
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 1 : -1]; // fcFinite
+
+
+  int foo() {
+    int a = 1; // #decla
+    char A[__builtin_isfpclass(1.0f, a)];
+#if __cplusplus >= 202002L
+                                          // both-warning at -2 {{variable length arrays}} \
+                                          // both-note at -2 {{read of non-const variable 'a'}} \
+                                          // both-note@#decla {{declared here}}
+#endif
+  }
 }
 
 namespace signbit {



More information about the cfe-commits mailing list