Compiler probe fails if relative paths as passed through for unhandled args
Starting with 0.29.0, I had to set the compiler path explicitly even though I have configured intellisense with a compile_commands.json file. The compiler to use is in the compile_commands.json and so I would have expected that it would be automatically picked up. I also noticed that it doesn't fallback to a default compiler either. Is this expected?
Hi @ryan-holt-1 . Do you happen to have C_Cpp.default.compilerPath set? I'm able to repro with that set, but I'm unable to repro without it set. It seems to be using this value, even though it should not when compileCommands is also set. I have a fix for this, which should be available in our next insiders. However, if that is not set in your repro, could you provide additional information, such as the contents of your c_cpp_properties.json and any relevant settings?
Sorry for the late response. I do not have a c_cpp_properties.json. The only configuration I had, prior to 0.29.0, was to set
"C_Cpp.default.compileCommands"
in my workspace settings. Starting with 29.0, I got errors such as:
"cannot open source file "stddef.h""
which seemed to be because the system include paths were not being set. If I explicitly set
"C_Cpp.default.compilerPath"
in my workspace settings, then the system includes get resolved and the errors go away.
This does not seem to be fixed for me in 0.30.0 insiders. In fact, now it seems that I do not have a workaround because now it does not fallback to the C_Cpp.default.compilerPath. For some reason, it is still not getting the compiler from the compile_commands.json. When I look at the logs, I see Attempting to get defaults from compiler found on the machine:. The compiler it finds is "gcc" but but my compile_commands.json specifies "g++". In 0.29.0, when I manually supplied "g++" it got used -- now it doesn't.
Hi @ryan-holt-1 . I don't currently have a repro for what you are describing. A scenario involving only C_Cpp.default.compileCommands seems to be working for me. Could you please provide any/all C_Cpp related settings, the output of the C/C++: Log Diagnostics command while a misconfigured file is open, and the output of the C/C++ channel leading up to the issue?
Note that the Attempting to get defaults from compiler found on the machine: message may appear for compilers other than the one being used to configure a particular translation unit (i.e. the default detected compiler).
I attached bad.txt and good.txt. They show the log output for 0.30.0 and 0.29.0, respectively.
Notice that in bad.txt I get Attempting to get defaults from compiler found on the machine: but in good.txt I get Attempting to get defaults from compiler in "compilerPath" property:. I also attached a single entry in my compile_commands.json.
Here are my settings:
"C_Cpp.default.compileCommands": "/local-ssd/ryanholt/GrowMatrix/compile_commands.json",
"C_Cpp.intelliSenseCachePath": "/local-ssd/ryanholt/GrowMatrix/.vscode-cpptools",
"C_Cpp.intelliSenseCacheSize": 25600,
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.browse.databaseFilename": "/local-ssd/ryanholt/GrowMatrix/.vscode-cpptools/browse.vc.db",
"C_Cpp.default.intelliSenseMode": "gcc-x64",
"C_Cpp.default.compilerPath": "/mathworks/hub/3rdparty/internal/5566149/glnxa64/gcc-8.3.0/bin/g++",
Ah.. I see in the logs:
Failed to query compiler. Falling back to 32-bit intelliSenseMode.
terminating child process: 93844
Failed to query compiler. Falling back to no bitness.
Any idea why this is happening?
Hi @ryan-holt-1 .
I'm not familiar with glnxa64. If that is not an x86 or x64 compiler, it would explain our inability to detect the bitness of the compiler, which we do to try to correct the IntelliSenseMode. This shouldn't be a problem. Those errors may also be due to other args preventing the compiler probe from working:
I noticed the following in the bad output:
Attempting to get defaults from compiler in compile_commands.json file: '/mathworks/hub/3rdparty/internal/5566149/glnxa64/gcc-8.3.0/bin/g++'
...
g++: error: unrecognized command line option ‘-ferror-limit=0’; did you mean ‘-finline-limit=’?
This error is coming from g++. It looks we're getting an error due to this command line arg not being accepted by the compiler. If you resolve this error, does it clear up the other issues?
Could you also provide the output of the C/C++: Log Diagnostics command? That would indicate which compiler was used, and all of the information used to set up the translation unit.
I removed -ferror-limit=0 from my compile_commands.json but I still see the same problem. Here is the output of C/C++: Log Diagnostics:
-------- Diagnostics - 8/5/2020, 2:33:45 PM
Version: 0.30.0-insiders
Current Configuration:
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "gnu18",
"compileCommands": "/local-ssd/ryanholt/GrowMatrix/compile_commands.json",
"compilerArgs": [],
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "/local-ssd/ryanholt/GrowMatrix/.vscode-cpptools/browse.vc.db"
}
}
Translation Unit Mappings:
[ /local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform/dom_core/lowering/scalarize/rules/RuleConcatenationLoopConstructor.cpp ]:
/local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform/dom_core/lowering/scalarize/rules/RuleConcatenationLoopConstructor.cpp
Translation Unit Configurations:
[ /local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform/dom_core/lowering/scalarize/rules/RuleConcatenationLoopConstructor.cpp ]:
Process ID: 23049
Memory Usage: 474 MB
Includes:
/local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform/export/include
/local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform/include
/local-ssd/ryanholt/GrowMatrix/matlab/src/cgir_xform
/local-ssd/ryanholt/GrowMatrix/matlab/derived/glnxa64/src/include
/local-ssd/ryanholt/GrowMatrix/matlab/src/include
/local-ssd/ryanholt/GrowMatrix/matlab/derived/glnxa64/builtin2_impls/cgir_xform_builtinimpl/builtin1/include
/local-ssd/ryanholt/GrowMatrix/matlab/derived/glnxa64/builtin2_impls/cgir_xform_builtinimpl/builtin1
/local-ssd/ryanholt/mathworks-hub/3rdparty/R2020b/5500384/glnxa64/boost/include
/local-ssd/ryanholt/mathworks-hub/3rdparty/R2021a/5742754/glnxa64/cpp11compat/include
/local-ssd/ryanholt/mathworks-hub/3rdparty/R2020b/5657608/glnxa64/gmp/include
/local-ssd/ryanholt/mathworks-hub/3rdparty/R2020b/5657608/glnxa64/mpfr/include
/usr/include/c++/8
/usr/include/x86_64-linux-gnu/c++/8
/usr/local/include
/usr/include
/usr/include/x86_64-linux-gnu
Defines:
BUILDING_CGIR_XFORM
MX_INTERLEAVED_COMPLEX
MODULE_VERSION_SYMBOL=libmwcgir_xform_version
MODULE_DATE_SYMBOL=libmwcgir_xform_build_date
mw_test_main=main
NEEDS_MX_ERRWARN_MSG_ID_AND_TXT
NEEDS_CODECVT_PREALLOCATED_BUFFER
NEEDS_SL_SERVICES_UNICODE_CONVERSIONS
NEEDS_ICU_EXT_API
BOOST_CB_DISABLE_DEBUG
BOOST_ASIO_DISABLE_EVENTFD
BOOST_THREAD_FUTURE=unique_future
BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
BOOST_SPIRIT_THREADSAFE
PHOENIX_THREADSAFE
BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
BOOST_MPL_LIMIT_VECTOR_SIZE=30
BOOST_MPL_LIMIT_MAP_SIZE=30
NEEDS_BOOST_UNIQUE_PTR=1
BUILDING_CGIR_XFORM
_POSIX_C_SOURCE=199506L
NEEDS_MW_BUILTIN_MACROS
MWBOOST=mwboost
MWBOOST_132=mwboost_132
Standard Version: c++17
IntelliSense Mode: gcc-x64
Other Flags:
--g++
--gnu_version=90100
Total Memory Usage: 474 MB
@ryan-holt-1 Could you also post an updated C/C++ output with the command line arg corrected? I'd like to confirm there isn't another issue detected after that one was resolved. I suspect we may still be failing to probe glnxa64 g++.
Note that glnxa64 just means x64 Linux.
@ryan-holt-1 I've tried installing MATLAB with a trial license, but it did not appear to have installed that specific version of gcc/g++. Can you tell me what package you are using that installed this? Since the x64 bitness detection is not working with that compiler, it would appear to be something different than a standard x64 compiler (such as the one that would be installed to the default location on your system). We appear to be failing to probe this compiler for system includes and system defines.
Could you try invoking that compiler directly using the args we pass in order to probe it, and post the output? Those would be: -Wp,-v -E -dD -x c++ /dev/null . i.e.: g++ -Wp,-v -E -dD -x c++ /dev/null We also use most of the args provided by compile_commands.json, as they may influence compiler defaults, so a probing failure could also occur due to other incorrect args, such as referring to directories that do not exist for output, such as with -MF or -MT.
It is just the compiler we use for development -- it does not ship with MATLAB. My understanding is that it is just gcc 8.3 that ships with Debian 10: https://packages.debian.org/buster/gcc-8
I attached "probe.txt" with the result of running our compiler (with all the compile_commands.json arguments as well) with -Wp,-v -E -dD -x c++ /dev/null appended to the end.
probe.txt
What is confusing to me is that it worked fine in cpptools 0.28.3. It also worked in 0.29.0 if I specified C_Cpp.default.compilerPath.
What is confusing to me is that it worked fine in cpptools 0.28.3. It also worked in 0.29.0 if I specified C_Cpp.default.compilerPath.
The reason it no longer works in 0.30.0-insiders is due to a 'fix' for the fact that we should be honoring the compiler from compile_commands.json, even if C_Cpp.default.compilerPath is set.
Unfortunately, I'm not repro'ing this issue easily with what seem to be equivalent configurations. So, my questions are aimed at trying to figure out what is different with your environment. Once I can repro, I suspect this will be straight-forward to fix.
Could you try adding the -m32 or -m64 compiler switches (not both) when probing the compiler manually? Those should be accepted by a x64 or x86 compiler. If they are accepted manually, then the problem seems to be related to the probing command line we are generating, as we think those args are failing.
The reason it no longer works in 0.30.0-insiders is due to a 'fix' for the fact that we should be honoring the compiler from
compile_commands.json, even ifC_Cpp.default.compilerPathis set.
I guess I meant that I assume it still had to probe the compiler set by C_Cpp.default.compilerPath to get the system includes, no? The compiler I specified was the same as the one in the compile_commands.json.
I attached "probe2.txt" which is the same as "probe.txt" but I added -m64. It seems to have been accepted.
probe2.txt
I really appreciate your help with this.
I think the reason it didn't repro when using C_Cpp.default.compilerPath in 0.29.0 is because we would probe that compiler for defaults without including the args present in your compiler_commands.json. With compile_commands.json, we probe the compiler separately for each different set of relevant arguments, as the build system could hypothetically be configuring the compiler differently on a per file basis.
Given that your compiler is accepting -m64 when you invoke it directly and not when we probe it, it seems like there is something wrong with the command line we are issuing to probe the compiler.
I'm going to add some additional logging, which should hopefully be available very soon (our next insiders). That will include the exact command we use to probe the compiler. I suspect that will lead to a fix, with your help. Thanks a lot for helping us investigate this!
Makes sense. Thanks! I'll look out for the next insiders.
Hi @Colengms,
I tried out the new insiders build. I see that it now outputs the probe command line:
Compiler probe command line: /mathworks/hub/3rdparty/internal/5566149/glnxa64/gcc-8.3.0/bin/g++ -c -MMD -MF ../../derived/glnxa64/obj/src/cg_ir/expr/ExprTools.d -MP -MT ../../derived/glnxa64/obj/src/cg_ir/expr/ExprTools.o -fno-strict-aliasing -O0 -pipe -pthread -fdebug-prefix-map=/local-ssd/ryanholt/CDTC= -fPIC -std=c++17 -fvisibility=hidden -g -fno-omit-frame-pointer -W -Wcast-align -Wno-misleading-indentation -Wno-implicit-fallthrough -Wall -Wwrite-strings -Wpointer-arith -Wcast-qual -Wno-unused -Woverloaded-virtual -Wnon-virtual-dtor -Wno-ignored-qualifiers -Wno-register -Wp,-v -E -dD -x c++ /dev/null
Running this in terminal seems to work just fine (see attached probe_bad.txt)
So, I started removing flags from my compile_commands.json to try and figure out which one is causing problems for cpptools. It turns out that if I remove all these flags:
-MMD -MF ../../derived/glnxa64/obj/src/cg_ir/expr/ExprTools.d -MP -MT ../../derived/glnxa64/obj/src/cg_ir/expr/ExprTools.o
then I no longer get:
Failed to query compiler. Falling back to 32-bit intelliSenseMode.
terminating child process: 93844
Failed to query compiler. Falling back to no bitness.
and everything is fine. These flags don't seem like they actually change the output of gcc (see attached probe_good.txt) so I wonder why they are causing the probe to fail? Do these flags need to be filtered from the probe command or is this some other bug?
Thanks, Ryan
Hi @ryan-holt-1 . I think the problem has to do with our current working directory when parsing command line args, and the fact that we pass those paths unmodified. Can you confirm that changing those paths to absolute paths addresses the issue? It looks like we could probably also strip -MP and -MF from our compiler probe.
That is indeed the problem. Converting to absolute path addresses the issue. Thanks.