This is a patch for bug 
Warnings should not be emitted with -M and -MM flags, because this mode is only used for generate MakeFiles.
yamaguchi on Apr 21 2017, 12:52 AM.Authored by
This also disables warnings for -MD and -MMD which shouldn't happen as we're actually compiling code here and are probably compiling a project. E.g. for people that use this mode to create dependency files while initially building (to figure out when to rebuild each object), this will effectively force -w to the whole build process which is not good.
I would just manually check for -M and -MM where we only run the preprocessor and where adding -w is safe. Also please add another test that we actually get the warnings for -MD and another one for -MMD.
Otherwise this look good.