Repository: mesonbuild/meson

Issue:
MSVC cc.has_function() false negatives due to compiler flags

Problem `cc.has_function()` returns a false negative due to an intrinsic not being called with the correct set of parameters.

e.g.
```
Running compile:
Working directory:  E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w
Command line:  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe -INCREMENTAL:NO -I"E:/vcpkg_folders/master/installed/x64-windows/include" E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w\testfile.c /FeE:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w\output.exe /nologo /showIncludes /MD -nologo -DWIN32 -D_WINDOWS -W3 -utf-8 -MP -MD -O2 -Oi -Gy -DNDEBUG -Z7 /nologo /showIncludes /Od kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /link -machine:x64 -DEBUG -OPT:REF -OPT:ICF /LIBPATH:E:/vcpkg_folders/master/installed/x64-windows/lib 

Code:
 
        #define lrint meson_disable_define_of_lrint
        
        #include <limits.h>
        #undef lrint
        
        #ifdef __cplusplus
        extern "C"
        #endif
        char lrint (void);
        
        #if defined __stub_lrint || defined __stub___lrint
        fail fail fail this function is not going to work
        #endif
        
        int main(void) {
          return lrint ();
        }
Compiler stdout:
 cl : Command line warning D9030 : '/showIncludes' is incompatible with multiprocessing; ignoring /MP switch
testfile.c
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\limits.h
Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vcruntime.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\sal.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\concurrencysal.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vadefs.h
E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w\testfile.c(10): warning C4391: 'char lrint(void)': incorrect return type for intrinsic function, expected 'long'
E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w\testfile.c(10): warning C4392: 'char lrint(void)': incorrect number of arguments for intrinsic function, expected '1' arguments
E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-rel\meson-private\tmprnijo34w\testfile.c(17): error C2168: 'lrint': too few actual parameters for intrinsic function

Compiler stderr:
 cl : Command line warning D9025 : overriding '/O2' with '/Od'

Checking for function "lrint" with dependency -lm: NO 
```


while with debug flags

```
Running compile:
Working directory:  E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-dbg\meson-private\tmpomutgea3
Command line:  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe -INCREMENTAL -I"E:/vcpkg_folders/master/installed/x64-windows/include" E:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-dbg\meson-private\tmpomutgea3\testfile.c /FeE:\vcpkg_folders\master\buildtrees\gdk-pixbuf\x64-windows-dbg\meson-private\tmpomutgea3\output.exe /nologo /showIncludes /MDd -nologo -DWIN32 -D_WINDOWS -W3 -utf-8 -MP -D_DEBUG -MDd -Z7 -Ob0 -Od -RTC1 /nologo /showIncludes /Od kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /link -machine:x64 -debug /LIBPATH:E:/vcpkg_folders/master/installed/x64-windows/debug/lib 

Code:
 
        #define lrint meson_disable_define_of_lrint
        
        #include <limits.h>
        #undef lrint
        
        #ifdef __cplusplus
        extern "C"
        #endif
        char lrint (void);
        
        #if defined __stub_lrint || defined __stub___lrint
        fail fail fail this function is not going to work
        #endif
        
        int main(void) {
          return lrint ();
        }
Compiler stdout:
 cl : Command line warning D9030 : '/showIncludes' is incompatible with multiprocessing; ignoring /MP switch
testfile.c
Note: including file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\limits.h
Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vcruntime.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\sal.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\concurrencysal.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\vadefs.h

Compiler stderr:
 
Checking for function "lrint" with dependency -lm: YES 
```

How can I override the results of `cc.has_function()` or correct the behavior?


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -159,7 +159,7 @@ def get_compile_only_args(self) -> T.List[str]:
         return ['/c']
 
     def get_no_optimization_args(self) -> T.List[str]:
-        return ['/Od']
+        return ['/Od','/Oi-']
 
     def sanitizer_compile_args(self, value: str) -> T.List[str]:
         if value == 'none':


Test patch: