[clang] [clang] Introduce "binary" StringLiteral for #embed data (PR #127629)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 06:21:01 PST 2025


================
@@ -4965,9 +4966,9 @@ class EmbedExpr final : public Expr {
       assert(EExpr && CurOffset != ULLONG_MAX &&
              "trying to dereference an invalid iterator");
       IntegerLiteral *N = EExpr->FakeChildNode;
-      StringRef DataRef = EExpr->Data->BinaryData->getBytes();
       N->setValue(*EExpr->Ctx,
-                  llvm::APInt(N->getValue().getBitWidth(), DataRef[CurOffset],
+                  llvm::APInt(N->getValue().getBitWidth(),
+                              EExpr->Data->BinaryData->getCodeUnit(CurOffset),
----------------
Fznamznon wrote:

I wish it did. This particular line helps for generic case of `#embed`  inside of an initializer list. The rest that this patch is adding is for #embed "fast path" where we simply put StringLiteral to the initializer list instead of EmbedExpr when a single #embed is used to initialize char array.
When we do that, the iterators of EmbedExpr won't be in use and the fail from https://github.com/llvm/llvm-project/issues/119256 is still in place.

https://github.com/llvm/llvm-project/pull/127629


More information about the cfe-commits mailing list