Skip to content

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

Description

@joewallwork

Consider the dot_with_bindings_O0 test and make the following edits:

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
         ^
<stdin>:1:1: note: scanning from here
 0.0
^
<stdin>:1:2: note: possible intended match here
 0.0
 ^

Input file: <stdin>
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfortranRelated to Enzyme's Fortran bindings

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions