================ @@ -791,10 +791,26 @@ class Expr : public ValueStmt { const Expr *PtrExpression, ASTContext &Ctx, EvalResult &Status) const; - /// If the current Expr can be evaluated to a pointer to a null-terminated - /// constant string, return the constant string (without the terminating - /// null). - std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const; + class StringEvalResult { + std::string Storage; + const StringLiteral *SL; + uint64_t Offset; + + public: + StringEvalResult(std::string Contents); + StringEvalResult(const StringLiteral *SL, uint64_t Offset); + + llvm::StringRef getString() const; + bool getStringLiteral(const StringLiteral *&SL, uint64_t &Offset) const; + }; ---------------- apple-fcloutier wrote:
This is a polite `union` of `std::string` and `StringLiteral`: `Storage` is empty when `SL` is set, and vice versa. `getString()` encapsulates useful logic to decide how to get a `StringRef` back, which I think justifies having a separate type instead of an aggregate. I will add a comment on top of it. https://github.com/llvm/llvm-project/pull/135864 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits