[clang] 1c4a98f - [clang][bytecode] Fix discarded builtin_complex (#180539)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 20:21:05 PST 2026


Author: Timm Baeder
Date: 2026-02-10T05:21:00+01:00
New Revision: 1c4a98f7687f328d9c0efb367758b0c046d5fb62

URL: https://github.com/llvm/llvm-project/commit/1c4a98f7687f328d9c0efb367758b0c046d5fb62
DIFF: https://github.com/llvm/llvm-project/commit/1c4a98f7687f328d9c0efb367758b0c046d5fb62.diff

LOG: [clang][bytecode] Fix discarded builtin_complex (#180539)

This is the only builtin that returns a non-primitive type I think.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index a0138c402e143..b981cd3c7090d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5212,10 +5212,8 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
   if (!this->emitCallBI(E, BuiltinID, E))
     return false;
 
-  if (DiscardResult && !ReturnType->isVoidType()) {
-    assert(ReturnT);
-    return this->emitPop(*ReturnT, E);
-  }
+  if (DiscardResult && !ReturnType->isVoidType())
+    return this->emitPop(ReturnT.value_or(PT_Ptr), E);
 
   return true;
 }

diff  --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp
index 68a8e78d5b25b..4440f201bb059 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -319,6 +319,8 @@ namespace Builtin {
 
 
   constexpr _Complex float C = __builtin_complex(10.0f, 20.0); // both-error {{arguments are of 
diff erent types}}
+
+  constexpr int Discarded = (__builtin_complex(1., 2.), 12);
 }
 
 namespace Cmp {


        


More information about the cfe-commits mailing list