================
@@ -1972,6 +1994,29 @@ TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const
ASTContext &C,
return new (Mem) TypeTraitExpr(EmptyShell(), IsStoredAsBool);
}
+std::string TypeTraitExpr::getStringValue() const {
+ assert(isStoredAsStringLiteral() && "not a string-valued type trait");
+ const APValue &Value = getAPValue();
+ assert(Value.isArray() && !Value.hasArrayFiller() &&
+ "expected a fully initialized string value");
+
+ std::string Str(Value.getArrayInitializedElts(), '\0');
+ for (auto [I, Char] : llvm::enumerate(Str))
+ Char = static_cast<char>(
+ Value.getArrayInitializedElt(I).getInt().getZExtValue());
+ return Str;
+}
+
+StringLiteral *
+TypeTraitExpr::createStringLiteral(const ASTContext &Context) const {
+ std::string Str = getStringValue();
+ llvm::APInt Size(Context.getTypeSize(Context.getSizeType()), Str.size() + 1);
+ QualType ArrayTy = Context.getConstantArrayType(
+ Context.CharTy.withConst(), Size, nullptr, ArraySizeModifier::Normal, 0);
+ return StringLiteral::Create(Context, Str, StringLiteralKind::Ordinary,
+ /*Pascal=*/false, ArrayTy, getBeginLoc());
+}
----------------
cor3ntin wrote:
I wonder if we can create the literal, then call EvaluateAsLValue on it and
store the resulting APValue
https://github.com/llvm/llvm-project/pull/236294
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits