================
@@ -2658,6 +2658,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
     Address Addr =
         SourceLVal.getAddress().withElementType(CGF.ConvertTypeForMem(DestTy));
     LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy);
+    if (SourceLVal.isVolatileQualified())
+      DestLV.getQuals().addVolatile();
----------------
efriedma-quic wrote:

Interesting.

The standard specification for std::bit_cast doesn't actually say what happens 
if the operand is volatile.

Consider the following example:

```
volatile double z1;
volatile long long z2;
void f() {
    __builtin_bit_cast(long long, z1);
    __builtin_bit_cast(long long, z2);
}
```

MSVC optimizes the casts away.  gcc preserves the casts.  It also preserves the 
types of the loads: it generates movsd when the operand is a double, and an 
integer mov when the operand is a "long long".

https://github.com/llvm/llvm-project/pull/231830
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to