[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

Axel Lundberg via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 12 04:26:38 PDT 2024


================
@@ -5571,11 +5571,52 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
       break;
     }
 
-    RValue RV = EmitAnyExpr(E->getRHS());
+    llvm::Value *Previous = nullptr;
----------------
Zonotora wrote:

I would also like to have it work similar to how EmitCompoundAssignmentLValue works, however it doesn't seem completely trivial to make this change? Maybe it is better suited in its own PR as well? But I can definitely convert:
```cpp
if (E->getLHS()->refersToBitField()) {
      // Get the RHS before scalar conversion.
  if (auto *ICE = GetOriginalRHSForBitfieldAssignment(E)) {
    SrcType = ICE->getSubExpr()->getType();
    Previous = EmitScalarExpr(ICE->getSubExpr());
    // Pass default ScalarConversionOpts to avoid emitting
    // integer sanitizer checks as E refers to bitfield.
    llvm::Value *RHS = EmitScalarConversion(
        Previous, SrcType, ICE->getType(), ICE->getExprLoc());
    RV = RValue::get(RHS);
  }
}
```
to something like:
```cpp
if (E->getLHS()->refersToBitField())
  Previous = EmitForOriginalRHSBitfieldAssignment(E, &RHS));
```
to at least de-duplicate some parts of it...

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


More information about the cfe-commits mailing list