Issue 237703
Summary [OpenMPOpt] Deduplicating omp_get_partition_place_nums replaces the output buffer with a constant ident_t
Labels openmp, miscompilation, generated by fuzzer
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/81Mn5xjWd
alive: https://alive2.llvm.org/ce/z/w-aiLx

```llvm
; Model of omp_get_partition_place_nums for a one-place partition {0}.
@first = global i32 -1
@second = global i32 -1

define void @omp_get_partition_place_nums(ptr %place_nums) {
  store i32 0, ptr %place_nums, align 4
  ret void
}

define i32 @main() {
  call void @omp_get_partition_place_nums(ptr @first)
  call void @omp_get_partition_place_nums(ptr @second)
  %place = load i32, ptr @first, align 4
  ret i32 %place
}

!llvm.module.flags = !{!0}
!0 = !{i32 7, !"openmp", i32 51}
```

```console
$ opt -S -passes=openmp-opt-cgscc issue-repro.ll
...
%struct.ident_t = type { i32, i32, i32, i32, ptr }

@first = global i32 -1
@second = global i32 -1
@0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8

; Function Attrs: nounwind
define void @omp_get_partition_place_nums(ptr %place_nums) #0 {
  store i32 0, ptr %place_nums, align 4
  ret void
}

define i32 @main() {
  call void @omp_get_partition_place_nums(ptr @1)
  %place = load i32, ptr @first, align 4
  ret i32 %place
}

attributes #0 = { nounwind }

!llvm.module.flags = !{!0}

!0 = !{i32 7, !"openmp", i32 51}

$ alive-tv --disable-undef-input --disable-poison-input -passes=openmp-opt-cgscc issue-repro.ll
...
Transformation doesn't verify!

ERROR: Source is more defined than target

Example:

Source:
void = function did not return!

...

Target:
  >> Jump to %#0
void = function did not return!

...
Summary:
  1 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors

$ opt -S -passes=openmp-opt-cgscc -openmp-opt-disable issue-repro.ll
...
@first = global i32 -1
@second = global i32 -1

define void @omp_get_partition_place_nums(ptr %place_nums) {
  store i32 0, ptr %place_nums, align 4
  ret void
}

define i32 @main() {
 call void @omp_get_partition_place_nums(ptr @first)
  call void @omp_get_partition_place_nums(ptr @second)
  %place = load i32, ptr @first, align 4
  ret i32 %place
}

!llvm.module.flags = !{!0}

!0 = !{i32 7, !"openmp", i32 51}
```

### suggested fix
Remove `OMPRTL_omp_get_partition_place_nums` from `DeduplicableRuntimeCallIDs` in `OpenMPOpt::deduplicateRuntimeCalls`.
This routine writes through its `int *` parameter, so calls with different output buffers must not be deduplicated.
The `ptr == IdentPtr` checks also mistake that buffer for a location argument with opaque pointers and replace it with a constant `ident_t` global.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to