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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 14:28:06 PST 2024


================
@@ -5571,11 +5571,50 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
       break;
     }
 
-    RValue RV = EmitAnyExpr(E->getRHS());
+    llvm::Value *Previous = nullptr;
+    RValue RV;
+    QualType SrcType = E->getRHS()->getType();
+    // Check if LHS is a bitfield and sanitizer checks are enabled
+    if (E->getLHS()->refersToBitField() &&
+        SanOpts.hasOneOf(SanitizerKind::ImplicitConversion |
+                         SanitizerKind::ImplicitBitfieldConversion)) {
----------------
zygoloid wrote:

```suggestion
        SanOpts.hasOneOf(SanitizerKind::ImplicitBitfieldConversion)) {
```
No need to check for the containing group; that should be handled automatically.

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


More information about the cfe-commits mailing list