I had this same issue using QtCreator 4.11.2 in MSYS2, but trying to use the MSYS2 GCC (package msys/gcc) instead of the default mingw64/gcc.
If I select (auto-detected) MSYS2 GCC as the compiler in the kit configuration, then the inline compilation messages indicate that stdio.h cannot be found, and under Tools > C++ > Inspect C++ Code Model, the field "BuiltinPath", which is supposed to have the path to system includes, shows as blank.
I partially fixed this, after reading this thread, by setting the kit's sysroot to be the path of my MSYS2 installation.
Setting sysroot to F:\Prog\msys64 caused the Clang Code Model's BuiltinPath to be detected correctly as F:/Prog/msys64/usr/include .
This causes #include <stdio.h> to be handled correctly, but #include <stddef.h> still fails. Because that file is in F:\Prog\msys64\usr\lib\gcc\x86_64-pc-msys\9.3.0\include .
As a workaround I added F:\Prog\msys64\usr\lib\gcc\x86_64-pc-msys\9.3.0\ to the INCLUDEPATH for Qmake, or the includes list for external project. But this is not really a desirable solution.
Furthermore, setting this sysroot causes debugging with GDB to fail as it can no longer find C:\Windows\system32 for DLLs that the binary depends on. So in the end I reverted the sysroot to blank and also added F:\Prog\msys64\usr\include to INCLUDEPATH.
Is there any way to manually configure what shows up under BuiltinPath so I can put the right paths there? Should it be considered a bug that qtcreator does not correctly set BuiltinPath without manual intervention?