[clang] 6906c5c - [clang][bytecode] Fix __builtin_nan* for non-primitive arrays (#181326)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 01:11:36 PST 2026
Author: Timm Baeder
Date: 2026-02-13T10:11:31+01:00
New Revision: 6906c5c0338b74750bba745725a1254d918620f0
URL: https://github.com/llvm/llvm-project/commit/6906c5c0338b74750bba745725a1254d918620f0
DIFF: https://github.com/llvm/llvm-project/commit/6906c5c0338b74750bba745725a1254d918620f0.diff
LOG: [clang][bytecode] Fix __builtin_nan* for non-primitive arrays (#181326)
They might've been casted, so we need t check for it, not assert.
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2f86877d31ffb..518738414de6b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -411,7 +411,8 @@ static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
if (!CheckLoad(S, OpPC, Arg))
return false;
- assert(Arg.getFieldDesc()->isPrimitiveArray());
+ if (!Arg.getFieldDesc()->isPrimitiveArray())
+ return Invalid(S, OpPC);
// Convert the given string to an integer using StringRef's API.
llvm::APInt Fill;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 77ba9ca4ce05c..f4a6a0be062d4 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -391,6 +391,10 @@ namespace floating_comparison {
static_assert(UNORDERED(__builtin_nanf(""), __builtin_inff()));
static_assert(UNORDERED(__builtin_nanl(""), 1.0L));
static_assert(UNORDERED(__builtin_nanl(""), __builtin_infl()));
+
+ struct {
+ } const s;
+ static_assert(__builtin_nan((const char *)&s) == 0); // both-error {{not an integral constant expression}}
}
namespace fpclassify {
More information about the cfe-commits
mailing list