dtcxzyw wrote:

> This change broke a couple of ubsan tests on i686 on Windows (i.e. a 32 bit 
> environment): 
> https://github.com/mstorsjo/llvm-mingw/actions/runs/14527591706/job/40770945907
> 
> The failing tests are 
> https://github.com/llvm/llvm-project/blob/llvmorg-20.1.3/compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
>  and 
> https://github.com/llvm/llvm-project/blob/llvmorg-20.1.3/compiler-rt/test/ubsan/TestCases/ImplicitConversion/bitfield-conversion.c.
> 
> The diff in ubsan output from `abs.cpp` looks like this:
> 
> ```diff
> @@ -6,7 +6,7 @@
>  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
> compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:19:18 
>  compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:20:8: runtime error: negation 
> of -2147483648 cannot be represented in type 'long'; cast to an unsigned type 
> to negate this value to itself
>  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
> compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:20:8 
> -compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:24:19: runtime error: negation 
> of -9223372036854775808 cannot be represented in type 'long long'; cast to an 
> unsigned type to negate this value to itself
> +compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:24:19: runtime error: negation 
> of 14963666063463584 cannot be represented in type 'long long'; cast to an 
> unsigned type to negate this value to itself
>  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
> compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:24:19 
> -compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:25:9: runtime error: negation 
> of -9223372036854775808 cannot be represented in type 'long long'; cast to an 
> unsigned type to negate this value to itself
> +compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:25:9: runtime error: negation 
> of 8880086229349853276 cannot be represented in type 'long long'; cast to an 
> unsigned type to negate this value to itself
>  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
> compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:25:9 
> ```

IR output is correct.
```
bin/clang --target=i686-w64-windows-gnu -emit-llvm -S 
-fsanitize=signed-integer-overflow -O3 
-fsanitize-recover=signed-integer-overflow -w -o - 
/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/clang/test/CodeGen/AArch64/ubsan-handler-pass-by-ref.c
; ModuleID = 
'/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/clang/test/CodeGen/AArch64/ubsan-handler-pass-by-ref.c'
source_filename = 
"/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/clang/test/CodeGen/AArch64/ubsan-handler-pass-by-ref.c"
target datalayout = 
"e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-w64-windows-gnu"

@.src = private unnamed_addr constant [111 x i8] 
c"/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/clang/test/CodeGen/AArch64/ubsan-handler-pass-by-ref.c\00",
 align 1
@0 = private unnamed_addr constant { i16, i16, [12 x i8] } { i16 0, i16 13, [12 
x i8] c"'long long'\00" }
@1 = private unnamed_addr global { { ptr, i32, i32 }, ptr } { { ptr, i32, i32 } 
{ ptr @.src, i32 17, i32 19 }, ptr @0 }

; Function Attrs: nounwind memory(read, inaccessiblemem: readwrite)
define dso_local noundef i32 @main() local_unnamed_addr #0 {
entry:
  %tmp = alloca i64, align 8
  store i64 -9223372036854775808, ptr %tmp, align 8, !nosanitize !5
  %0 = ptrtoint ptr %tmp to i32, !nosanitize !5
  call void @__ubsan_handle_negate_overflow(ptr nonnull @1, i32 %0) #2, 
!nosanitize !5
  ret i32 0
}

; Function Attrs: memory(read, inaccessiblemem: readwrite) uwtable
declare dso_local void @__ubsan_handle_negate_overflow(ptr, i32) 
local_unnamed_addr #1

attributes #0 = { nounwind memory(read, inaccessiblemem: readwrite) 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="pentium4" 
"target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { memory(read, inaccessiblemem: readwrite) uwtable }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2}
!llvm.linker.options = !{!3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"NumRegisterParameters", i32 0}
!1 = !{i32 1, !"wchar_size", i32 2}
!2 = !{i32 1, !"MaxTLSAlign", i32 65536}
!3 = !{!"/DEFAULTLIB:libclang_rt.ubsan_standalone.a"}
!4 = !{!"clang version 21.0.0git"}
!5 = !{}
```
And the codegen looks good.
```
.def    @feat.00;
        .scl    3;
        .type   0;
        .endef
        .globl  @feat.00
.set @feat.00, 1
        .file   "ubsan-handler-pass-by-ref.c"
        .def    _main;
        .scl    2;
        .type   32;
        .endef
        .text
        .globl  _main                           # -- Begin function main
        .p2align        4
_main:                                  # @main
# %bb.0:                                # %entry
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-8, %esp
        subl    $8, %esp
        calll   ___main
        movl    $-2147483648, 4(%esp)           # imm = 0x80000000
        movl    $0, (%esp)
        movl    %esp, %eax
        pushl   %eax
        pushl   $L___unnamed_1
        calll   ___ubsan_handle_negate_overflow
        addl    $8, %esp
        xorl    %eax, %eax
        movl    %ebp, %esp
        popl    %ebp
        retl
                                        # -- End function
        .section        .rdata,"dr"
L_.src:                                 # @.src
        .asciz  
"/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/clang/test/CodeGen/AArch64/ubsan-handler-pass-by-ref.c"

        .p2align        2, 0x0                          # @0
L___unnamed_2:
        .short  0                               # 0x0
        .short  13                              # 0xd
        .asciz  "'long long'"

        .data
        .p2align        2, 0x0                          # @1
L___unnamed_1:
        .long   L_.src
        .long   17                              # 0x11
        .long   19                              # 0x13
        .long   L___unnamed_2

        .section        .drectve,"yni"
        .ascii  " /DEFAULTLIB:libclang_rt.ubsan_standalone.a"
        .addrsig
```


https://github.com/llvm/llvm-project/pull/135135
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to