Skip to content

[clang][clangIR] Missing assignment in loop, which may comes from wrong TBAA. #133404

Open
@youngHC

Description

@youngHC

While testing real code during work, I found a potential bug, here is my code:

https://godbolt.org/z/fzd71aPcx

It can be observed that the assignment to cmd.regOp inside the loop actually affects subsequent logic. However, in assembly, this assignment operation is removed. In fact, it has already been eliminated at the IR generation stage.

I suspect this is related to an incorrect TBAA upon memcpy. Below are the memcpy instruction and the current TBAA.

BTW, this occurs regardless of the clang version.

call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 4 dereferenceable(56) %astEntry.i, ptr noundef nonnull readonly align 8 dereferenceable(56) %stRegCmd, i32 56, i1 false), !tbaa.struct !11

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, !"target-abi", !"ilp32"}
!2 = !{i32 6, !"riscv-isa", !3}
!3 = !{!"rv32i2p1_m2p0_a2p1_c2p0_zmmul1p0"}
!4 = !{i32 8, !"SmallDataLimit", i32 8}
!5 = !{!"clang version 19.0.0git"}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 16}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 16, !7, i64 17,!7, i64 18, !7, i64 19, !7, i64 20}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 4}
!15 = !{i64 0, i64 56, !6}
!16 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!17 = !{i64 0, i64 1, !6, i64 4, i64 0, !6}
!18 = distinct !{!18, !12}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClangIRAnything related to the ClangIR projectclangClang issues not falling into any other categorymiscompilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions