EnzymeAD / EnzymeAD/Enzyme

Flang plugin doesn't raise an error with `-O0` and intrinsics

Open
#3,138 0 comments 0 reactions 0 assignees View on GitHub
bug fortran
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
2d 4h
Merged PRs (30d)
22

Description

Consider the [`dot_with_bindings_O0`](https://github.com/EnzymeAD/Enzyme/blob/main/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90) test and make the following edits:
```diff
diff --git a/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90 b/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90
index 383d7c7a..24d76f00 100644
--- a/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90
+++ b/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90
@@ -1,6 +1,5 @@
! REQUIRES: fortran
! UNSUPPORTED: ifx
-! RUN: %fc -flto -O0 -c %loadFortran %s -o /dev/stdout | %opt %loadEnzyme %enzyme -o %t.ll && %fc -flto -O0 %t.ll -o %t1 && %t1 | FileCheck %s
! RUN: %if flangenzyme %{ %fc -O0 %loadFortran %loadFlangEnzyme %s -o %t2 && %t2 | FileCheck %s %}

! NOTE: This test is only configured to run with the flang compiler at -O0
@@ -67,15 +66,7 @@ contains
real, dimension(n), intent(in) :: a
real, dimension(n), intent(in) :: b
real, intent(in) :: c
- integer :: i
- ! TODO: Use the `dot_product` intrinsic.
- ! Requires accounting for `_FortranADotProductReal4` for this to work
- ! at -O0
- ! dot = dot_product(a, b) + c
- dot = c
- do i = 1, n
- dot = dot + a(i) * b(i)
- end do
+ dot = dot_product(a, b) + c
end function dot

end program main
```
That is, only consider running with the Flang plugin and attempt to differentiate the `dot_product` intrinsic.

Running locally, I get the following runtime error
```
[0/2] Re-checking globbed directories...
[0/2] Running enzyme fortran integration tests
FAIL: Enzyme :: Fortran/ReverseMode/dot_with_bindings_O0.f90 (14 of 15)
******************** TEST 'Enzyme :: Fortran/ReverseMode/dot_with_bindings_O0.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: flang -O0 -I/home/joe/tools/enzyme/build/flang/modules -fpass-plugin=/home/joe/tools/enzyme/build/flang/Enzyme/FlangEnzyme-21.so /home/joe/tools/enzyme/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90 -o /
home/joe/tools/enzyme/build/flang/test/Fortran/ReverseMode/Output/dot_with_bindings_O0.f90.tmp2 && /home/joe/tools/enzyme/build/flang/test/Fortran/ReverseMode/Output/dot_with_bindings_O0.f90.tmp2 | FileCheck /home/joe/tools/enzyme
/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90
+ flang -O0 -I/home/joe/tools/enzyme/build/flang/modules -fpass-plugin=/home/joe/tools/enzyme/build/flang/Enzyme/FlangEnzyme-21.so /home/joe/tools/enzyme/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90 -o /home/joe/tools/
enzyme/build/flang/test/Fortran/ReverseMode/Output/dot_with_bindings_O0.f90.tmp2
+ /home/joe/tools/enzyme/build/flang/test/Fortran/ReverseMode/Output/dot_with_bindings_O0.f90.tmp2
+ FileCheck /home/joe/tools/enzyme/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90
/home/joe/tools/enzyme/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90:74:10: error: CHECK: expected string not found in input
! CHECK: 20.0
^
:1:1: note: scanning from here
0.0
^
:1:2: note: possible intended match here
0.0
^

Input file:
Check file: /home/joe/tools/enzyme/enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
1: 0.0
check:74'0 X~~~~ error: no match found
check:74'1 ? possible intended match
2: 0.0
check:74'0 ~~~~~
3: 1.0
check:74'0 ~~~~~
4: 0.0
check:74'0 ~~~~~
5: 0.0
check:74'0 ~~~~~
6: 1.0
check:74'0 ~~~~~
.
.
.
>>>>>>

--

********************
********************
Failed Tests (1):
Enzyme :: Fortran/ReverseMode/dot_with_bindings_O0.f90
```
i.e., the outputs are all zero. This should instead raise a compile-time error.

Contributor guide

Open the contributing guide

Research direction

Start with enzyme/test/Fortran/ReverseMode/dot_with_bindings_O0.f90 and its Flang plugin RUN line. Run the test to reproduce the zero outputs, then trace the plugin's handling of the dot_product intrinsic at -O0. Done means the test raises the expected compile-time error instead of producing zero outputs.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.