File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -6446,8 +6446,6 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
64466446 QualType ToType = E->getType ();
64476447 std::optional<PrimType> ToT = classify (ToType);
64486448
6449- assert (!DiscardResult && " Implement DiscardResult mode for bitcasts." );
6450-
64516449 if (ToType->isNullPtrType ()) {
64526450 if (!this ->discard (SubExpr))
64536451 return false ;
@@ -6463,12 +6461,24 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
64636461 }
64646462 assert (!ToType->isReferenceType ());
64656463
6464+ // Prepare storage for the result in case we discard.
6465+ if (DiscardResult && !Initializing && !ToT) {
6466+ std::optional<unsigned > LocalIndex = allocateLocal (E);
6467+ if (!LocalIndex)
6468+ return false ;
6469+ if (!this ->emitGetPtrLocal (*LocalIndex, E))
6470+ return false ;
6471+ }
6472+
64666473 // Get a pointer to the value-to-cast on the stack.
64676474 if (!this ->visit (SubExpr))
64686475 return false ;
64696476
6470- if (!ToT || ToT == PT_Ptr)
6471- return this ->emitBitCastPtr (E);
6477+ if (!ToT || ToT == PT_Ptr) {
6478+ if (!this ->emitBitCastPtr (E))
6479+ return false ;
6480+ return DiscardResult ? this ->emitPopPtr (E) : true ;
6481+ }
64726482 assert (ToT);
64736483
64746484 const llvm::fltSemantics *TargetSemantics = nullptr ;
Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ constexpr Init round_trip(const Init &init) {
3838 return bit_cast<Init>(bit_cast<Intermediate>(init));
3939}
4040
41+
42+ namespace Discarding {
43+ struct S { int a; };
44+ constexpr int f = (__builtin_bit_cast(int , 2 ), 0 );
45+ constexpr int f2 = (__builtin_bit_cast(S, 2 ), 0 );
46+ }
47+
4148namespace std {
4249enum byte : unsigned char {};
4350} // namespace std
You can’t perform that action at this time.
0 commit comments