[clang] ac795f0 - [clang][bytecode] Create fewer pointers in __builtin_nan() (#187990)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 23 02:59:45 PDT 2026
Author: Timm Baeder
Date: 2026-03-23T10:59:40+01:00
New Revision: ac795f0b0b3ba4a5cb3c1b9325b92e130814809b
URL: https://github.com/llvm/llvm-project/commit/ac795f0b0b3ba4a5cb3c1b9325b92e130814809b
DIFF: https://github.com/llvm/llvm-project/commit/ac795f0b0b3ba4a5cb3c1b9325b92e130814809b.diff
LOG: [clang][bytecode] Create fewer pointers in __builtin_nan() (#187990)
Check the elements directly for initialization state and keep track of
whether we found a NUL byte.
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 5f8bfcc452387..96c97d1df0f38 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -422,19 +422,23 @@ static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
// Convert the given string to an integer using StringRef's API.
llvm::APInt Fill;
std::string Str;
- assert(Arg.getNumElems() >= 1);
- for (unsigned I = 0;; ++I) {
- const Pointer &Elem = Arg.atIndex(I);
-
- if (!CheckLoad(S, OpPC, Elem))
+ unsigned ArgLength = Arg.getNumElems();
+ bool FoundZero = false;
+ for (unsigned I = 0; I != ArgLength; ++I) {
+ if (!Arg.isElementInitialized(I))
return false;
- if (Elem.deref<int8_t>() == 0)
+ if (Arg.elem<int8_t>(I) == 0) {
+ FoundZero = true;
break;
-
- Str += Elem.deref<char>();
+ }
+ Str += Arg.elem<char>(I);
}
+ // If we didn't find a NUL byte, diagnose as a one-past-the-end read.
+ if (!FoundZero)
+ return CheckRange(S, OpPC, Arg.atIndex(ArgLength), AK_Read);
+
// Treat empty strings as if they were zero.
if (Str.empty())
Fill = llvm::APInt(32, 0);
More information about the cfe-commits
mailing list