[clang] [clang][bytecode] Use in `Expr::tryEvaluateString` (PR #160118)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 23 00:35:27 PDT 2025
================
@@ -236,6 +236,48 @@ bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
}
+bool Context::evaluateString(State &Parent, const Expr *E,
+ std::string &Result) {
+ assert(Stk.empty());
+ Compiler<EvalEmitter> C(*this, *P, Parent, Stk);
+
+ auto PtrRes = C.interpretAsPointer(E, [&](const Pointer &Ptr) {
+ const Descriptor *FieldDesc = Ptr.getFieldDesc();
+ if (!FieldDesc->isPrimitiveArray())
+ return false;
+
+ if (!Ptr.isConst())
+ return false;
+
+ unsigned N = Ptr.getNumElems();
+ if (Ptr.elemSize() == 1 /* bytes */) {
+ const char *Chars = reinterpret_cast<const char *>(Ptr.getRawAddress());
+ unsigned Length = strnlen(Chars, N);
+ Result.assign(Chars, Length);
----------------
tbaederr wrote:
Indeed.
https://github.com/llvm/llvm-project/pull/160118
More information about the cfe-commits
mailing list