[clang] 2b4b721 - [clang][bytecode] Emit embed element casts directly (#152928)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 10 10:02:12 PDT 2025


Author: Timm Baeder
Date: 2025-08-10T19:02:08+02:00
New Revision: 2b4b721faf852a405b25064c0d3b59a2372efe2b

URL: https://github.com/llvm/llvm-project/commit/2b4b721faf852a405b25064c0d3b59a2372efe2b
DIFF: https://github.com/llvm/llvm-project/commit/2b4b721faf852a405b25064c0d3b59a2372efe2b.diff

LOG: [clang][bytecode] Emit embed element casts directly (#152928)

The element initializer is known to be an IntegerLiteral, the previous
signature of the lambda just didn't specify that. So we can also do the
cast directly instead of doing it via a Cast op.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 5275b86a57a47..8e651cf060620 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1932,15 +1932,10 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
               dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) {
         PrimType TargetT = classifyPrim(Init->getType());
 
-        auto Eval = [&](const Expr *Init, unsigned ElemIndex) {
-          PrimType InitT = classifyPrim(Init->getType());
-          if (!this->visit(Init))
+        auto Eval = [&](const IntegerLiteral *IL, unsigned ElemIndex) {
+          if (!this->emitConst(IL->getValue(), Init))
             return false;
-          if (InitT != TargetT) {
-            if (!this->emitCast(InitT, TargetT, E))
-              return false;
-          }
-          return this->emitInitElem(TargetT, ElemIndex, Init);
+          return this->emitInitElem(TargetT, ElemIndex, IL);
         };
         if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
           return false;


        


More information about the cfe-commits mailing list