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

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 10:28:23 PDT 2024


================
@@ -5571,11 +5571,52 @@ 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, if RHS contains an implicit cast expression
+    // we want to extract that value and potentially (if the bitfield sanitizer
+    // is enabled) use it to check for an implicit conversion.
+    if (E->getLHS()->refersToBitField()) {
+      // Get the RHS before scalar conversion.
+      if (auto *ICE = GetOriginalRHSForBitfieldSanitizer(E)) {
----------------
zygoloid wrote:

What do you think about renaming this to `GetOriginalRHSForBitfieldAssignment`, given that we now use it unconditionally for all lowering of bitfield assignments?

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


More information about the llvm-commits mailing list