Closed mattt-b closed 5 years ago
You can print the compilation flags rtags picked up for a specific file by calling rtags-compilation-flags
when inside that the file. What does it say?
You can print the compilation flags rtags picked up for a specific file by calling
rtags-compilation-flags
when inside that the file. What does it say?
It prints the command I provided/expect, including the -Wno-missing-braces
. If I run the command it lists I get no warnings/errors, but rtags still shows some in the diagnostics.
/usr/bin/cc -c -g -Wall -Wextra -pedantic -Wno-missing-braces -g /path/to/file
Hmm... Could you provide a minimal example plus your steps to reproduce this please.
Also run rdm with =-vv= (=rdm -vv=), and run rc "rc -c /usr/bin/cc -c -g -Wall -Wextra -pedantic -Wno-missing-braces -c MINIMAL_EXAMPLE.c -o minimal_example", than post the debug output of rdm here please.
Hmm... Could you provide a minimal example plus your steps to reproduce this please.
main.c
typedef struct Foo {
union {
int bar1;
int baz1;
};
union {
int bar2;
int baz2;
};
} Foo;
int main(void)
{
Foo test = {1, 2};
return 0;
}
compile_commands.json
[
{
"arguments": [
"cc",
"-c",
"-g",
"-Wno-missing-braces",
"-o",
"main",
"main.c"
],
"directory": "/home/matt/code/misc",
"file": "main.c"
}
]
To reproduce I just make any change anywhere which triggers populating rtags-diagnostics.
For the example I didn't add -Wall
but I still have -Wno-missing-braces
. This command compiles this file without error/warning, but rtags-diagnostics will list them, which flycheck-rtags picks up on.
Also run rdm with =-vv= (=rdm -vv=), and run rc "rc -c /usr/bin/cc -c -g -Wall -Wextra -pedantic -Wno-missing-braces -c MINIMAL_EXAMPLE.c -o minimal_example", than post the debug output of rdm here please.
rm -rf ~/.cache/rtags/*
Starting rdm -vv
:
listening /run/user/1000/rdm.socket
Running with 8 jobs, using args: -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option
Includepaths: "-isystem" /usr/lib/llvm-6.0/lib/clang/6.0.1/include/
rc -J compile_commands.json
Source::parse ( cc -c -g -Wno-missing-braces -o main main.c ) => List<String>(cc, -c, -g, -Wno-missing-braces, -o, main, main.c) /home/matt/code/misc/
Found compiler /usr/lib/llvm-6.0/bin/clang for cc
parsing argument 0 cc
parsing argument 1 -c
parsing argument 2 -g
parsing argument 3 -Wno-missing-braces
parsing argument 4 -o
parsing argument 6 main.c
Parsed Source(s) successfully: List<Source>(Source(/usr/bin/cc -c -g -Wno-missing-braces -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -DRTAGS -isystem /usr/lib/llvm-6.0/lib/clang/6.0.1/include/ -o /home/matt/code/misc/main /home/matt/code/misc/main.c Build: /home/matt/code/misc/))
Got 1 sources, and List<Path>(/home/matt/code/misc/main.c) from cc -c -g -Wno-missing-braces -o main main.c
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
Starting process for 1 /home/matt/code/misc/main.c 0x55e478dd6d30
Got handleIndexDataMessage
job got index data message 1 4 0x55e478dd6d30
[100%] 1/1 11:12:16 ~/code/misc/main.c in 5ms. (19 syms, 29 symNames, 0 includes, 1 of 1 files, symbols: 26 of 26, 378 cursors, 8148 bytes written) (4/0/1ms). (priority 0)
Jobs took 0.01s. We're using 9mb of memory.
Query opened 0 files for project /home/matt/code/misc/
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
Looks like it adds -Wall
on its' own even though I didn't have it in? That wouldn't bother me much, I usually use it, just left it out here as an example, but it is unexpected.
Opening emacs:
/usr/local/bin/rc --socket-file=/run/user/1000/rdm.socket -m --elisp
/usr/local/bin/rc --socket-file=/run/user/1000/rdm.socket --silent-query --silent -b -z -t128 --set-buffers=+/home/matt/code/misc/main.c
Adding a blank line to trigger populating diagnostics:
/home/matt/code/misc/.#main.c 0 was added
fm file added /home/matt/code/misc/.#main.c
/home/matt/code/misc/main.c 4 was modified
/home/matt/code/misc/main.c 4 was modified
/home/matt/code/misc/main.c 4 was modified
/home/matt/code/misc/main.c 4 was modified
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
Starting process for 2 /home/matt/code/misc/main.c 0x55e478dd6d30
onDirtyTimeout Set<unsigned int>(4) 1
Got handleIndexDataMessage
job got index data message 2 4 0x55e478dd6d30
[100%] 1/1 11:14:04 ~/code/misc/main.c in 4ms. (19 syms, 29 symNames, 0 includes, 1 of 1 files, symbols: 26 of 26, 378 cursors, 8148 bytes written) (3/1/0ms) (dirty,active). (priority 10)
Jobs took 0.03s. We're using 7mb of memory.
Query opened 0 files for project /home/matt/code/misc/
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
/home/matt/code/misc/.#main.c was removed 0
fm file removed /home/matt/code/misc/.#main.c
File is now showing two diagnostic errors- usused variable and missing braces.
Run rc -c /usr/bin/cc -c -g -Wno-missing-braces -o /home/matt/code/misc/main /home/matt/code/misc/main.c
which is the output of rtags-compilation-flags
:
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
Source::parse ( /usr/bin/cc -c -g -Wno-missing-braces -o /home/matt/code/misc/main /home/matt/code/misc/main.c ) => List<String>(/usr/bin/cc, -c, -g, -Wno-missing-braces, -o, /home/matt/code/misc/main, /home/matt/code/misc/main.c) /home/matt/code/misc/
parsing argument 0 /usr/bin/cc
parsing argument 1 -c
parsing argument 2 -g
parsing argument 3 -Wno-missing-braces
parsing argument 4 -o
parsing argument 6 /home/matt/code/misc/main.c
Parsed Source(s) successfully: List<Source>(Source(/usr/bin/cc -c -g -Wno-missing-braces -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -DRTAGS -isystem /usr/lib/llvm-6.0/lib/clang/6.0.1/include/ -o /home/matt/code/misc/main /home/matt/code/misc/main.c Build: /home/matt/code/misc/))
Got 1 sources, and List<Path>(/home/matt/code/misc/main.c) from /usr/bin/cc -c -g -Wno-missing-braces -o /home/matt/code/misc/main /home/matt/code/misc/main.c
Args are the same
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
Starting process for 3 /home/matt/code/misc/main.c 0x55e478dd6d30
Got handleIndexDataMessage
job got index data message 3 4 0x55e478dd6d30
[100%] 1/1 11:17:35 ~/code/misc/main.c in 5ms. (19 syms, 29 symNames, 0 includes, 1 of 1 files, symbols: 26 of 26, 378 cursors, 8148 bytes written) (4/0/1ms) (active). (priority 9)
Jobs took 0.02s. We're using 10mb of memory.
Query opened 0 files for project /home/matt/code/misc/
JobScheduler::startJobs jobCount 8 active 0
slots 8 daemonCount 0 active daemons 0
daemonSlots 0
rdm always enables -Wall, you can disable it with rdm --no-Wall. But you would need to delete the cache and reparse it. Use rc -W PROJECT
to delete the cache of project.
rdm always enables -Wall, you can disable it with rdm --no-Wall. But you would need to delete the cache and reparse it. Use
rc -W PROJECT
to delete the cache of project.
I thought the point of compile_commands.json
was to allow each project to be configured individually instead of globally in rdm - am I misunderstanding?
Either way rdm is not applying -Wno-missing-braces
(and there is no global rdm flag for it) which is what is currently affecting my code- is there a way to make that work or is it a bug/intended that it's not working?
There are just a view flags which are enabled by default (-ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option). All of which can be disabled.
rdm is applying those mentioned flags by default, you can see the final compile call in the output.
/usr/bin/cc -c -g -Wno-missing-braces -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -DRTAGS -isystem /usr/lib/llvm-6.0/lib/clang/6.0.1/include/ -o /home/matt/code/misc/main /home/matt/code/misc/main.c Build: /home/matt/code/misc/
The flag -Wall
which comes later, overrules the flag -Wno-missing-braces
thats a LLVM/Clang design implementation. ~If I remember correctly GCC behaviours similarly.~
clang -c -g -Wall -Wno-missing-braces -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -DRTAGS -isystem /usr/lib64/clang/7.0.1/include/ -o /home/cschwarzgruber/Developing/testing/c/main /home/cschwarzgruber/Developing/testing/c/main.c
/home/cschwarzgruber/Developing/testing/c/main.c:13:15: warning: suggest braces around initialization of subobject [-Wmissing-braces]
Foo test = {1, 2};
^
{}
/home/cschwarzgruber/Developing/testing/c/main.c:13:18: warning: suggest braces around initialization of subobject [-Wmissing-braces]
Foo test = {1, 2};
^
{}
/home/cschwarzgruber/Developing/testing/c/main.c:13:7: warning: unused variable 'test' [-Wunused-variable]
Foo test = {1, 2};
^
3 warnings generated.
vs.
clang -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -c -g -Wno-missing-braces -DRTAGS -isystem /usr/lib64/clang/7.0.1/include/ -o /home/cschwarzgruber/Developing/testing/c/main /home/cschwarzgruber/Developing/testing/c/main.c
/home/cschwarzgruber/Developing/testing/c/main.c:13:7: warning: unused variable 'test' [-Wunused-variable]
Foo test = {1, 2};
^
1 warning generated.
RTags should definitely put the default flags at the front, so individual flags can be turned off.
Ah perfect. I had no idea flag order mattered for clang, and I misunderstood the rdm flags- I thought --no-Wall
would remove -Wall
from my flags, as like an opposite --allow-Wpedantic
. I should have tested that myself.
So I can disable the global rdm flags with --no-Wall
, etc... And then still have them in each of my individual projects (and in the correct order) and it works exactly how I expected it to. I appreciate your assistance and patience.
Ah perfect. I had no idea flag order mattered for clang, and I misunderstood the rdm flags- I thought
--no-Wall
would remove-Wall
from my flags, as like an opposite--allow-Wpedantic
. I should have tested that myself.
And I should have read your comment in greater detail in the first place :-
So I can disable the global rdm flags with
--no-Wall
, etc... And then still have them in each of my individual projects (and in the correct order) and it works exactly how I expected it to. I appreciate your assistance and patience.
Exactly!
There are a few hardcoded (src/Source.cpp:187) flags which need to be removed in order to make gcc compile commands work with the clang compiler. This might indeed lead to some diagnostics errors but this can be worked out (most of the time) with the rdm
flag --enable-compiler-manager|-R
. That flag comes quite handy when you are cross-compiling some code for some embedded device, for instance.
TL;DR; To workaround the problem where the order of the -W flags matter when -Wall is added by CMake cd your project rc -W $PWD restart rdm with --no-Wall rc -J . reopen affected buffers in emacs
Describe the bug Rtags appears to completely ignore flags in compile_commands.json when processing diagnostics.
To Reproduce In a file that is compiled without
-Wall
initialize a variable but don't use it. Rtags will give an unused variable warning.Expected behavior Rtags to apply user flags when running diagnostic command. In particular my project is filled with errors because rtags ignores
-Wno-missing-braces
Screenshots/Backtrace If applicable, add screenshots or/and a backtrace.
Environment (please complete the following information):