[all-commits] [llvm/llvm-project] 708c8c: Fix "[clang][UBSan] Add implicit conversion check ...

Axel Lundberg via All-commits all-commits at lists.llvm.org
Mon Apr 8 12:30:49 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 708c8cd7435002027a2cc9b99a0916a3dc255d63
      https://github.com/llvm/llvm-project/commit/708c8cd7435002027a2cc9b99a0916a3dc255d63
  Author: Axel Lundberg <19574357+Zonotora at users.noreply.github.com>
  Date:   2024-04-08 (Mon, 08 Apr 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/docs/UndefinedBehaviorSanitizer.rst
    M clang/include/clang/Basic/Sanitizers.def
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CGExprScalar.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    M clang/test/CodeGen/catch-implicit-conversions-basics.c
    M clang/test/CodeGen/catch-implicit-conversions-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-integer-arithmetic-value-change-basics.c
    M clang/test/CodeGen/catch-implicit-integer-arithmetic-value-change-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-integer-conversions-basics.c
    M clang/test/CodeGen/catch-implicit-integer-conversions-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-integer-sign-changes-CompoundAssignOperator.c
    M clang/test/CodeGen/catch-implicit-integer-sign-changes-basics.c
    M clang/test/CodeGen/catch-implicit-integer-sign-changes-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-integer-sign-changes-incdec.c
    M clang/test/CodeGen/catch-implicit-integer-sign-changes.c
    M clang/test/CodeGen/catch-implicit-integer-truncations-CompoundAssignOperator.c
    M clang/test/CodeGen/catch-implicit-integer-truncations-basics-negatives.c
    M clang/test/CodeGen/catch-implicit-integer-truncations-basics.c
    M clang/test/CodeGen/catch-implicit-integer-truncations-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-integer-truncations.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncation-or-sign-change-CompoundAssignOperator.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncation-or-sign-change.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncations-basics-negatives.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncations-basics.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncations-incdec-basics.c
    M clang/test/CodeGen/catch-implicit-signed-integer-truncations-incdec.c
    M clang/test/CodeGen/catch-implicit-unsigned-integer-truncations-basics-negatives.c
    M clang/test/CodeGen/catch-implicit-unsigned-integer-truncations-basics.c
    A clang/test/CodeGen/ubsan-bitfield-conversion.c
    A clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp
    M clang/test/Driver/fsanitize.c
    M compiler-rt/lib/ubsan/ubsan_handlers.cpp
    M compiler-rt/lib/ubsan/ubsan_handlers.h
    A compiler-rt/test/ubsan/TestCases/ImplicitConversion/bitfield-conversion.c

  Log Message:
  -----------
  Fix "[clang][UBSan] Add implicit conversion check for bitfields" (#87761)

Fix since #75481 got reverted.

- Explicitly set BitfieldBits to 0 to avoid uninitialized field member
for the integer checks:
```diff
-       llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first)};
+      llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first),
+      llvm::ConstantInt::get(Builder.getInt32Ty(), 0)};
```
- `Value **Previous` was erroneously `Value *Previous` in
`CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment`, fixed now.
- Update following:
```diff
-     if (Kind == CK_IntegralCast) {
+     if (Kind == CK_IntegralCast || Kind == CK_LValueToRValue) {
```
CK_LValueToRValue when going from, e.g., char to char, and
CK_IntegralCast otherwise.
- Make sure that `Value *Previous = nullptr;` is initialized (see
https://github.com/llvm/llvm-project/commit/1189e87951e59a81ee097eae847c06008276fef1)
- Add another extensive testcase
`ubsan/TestCases/ImplicitConversion/bitfield-conversion.c`

---------

Co-authored-by: Vitaly Buka <vitalybuka at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list