From: Yuka Takahashi Date: Fri, 16 Jun 2017 16:01:13 +0000 (+0000) Subject: Fix a bug that warnings generated with -M or -MM flags X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2aee8d9aa73510087430ea6ee45810e3457e87bf;p=clang Fix a bug that warnings generated with -M or -MM flags This is a patch for bug: https://bugs.llvm.org/show_bug.cgi?id=6817 Warnings should not be emitted with -M and -MM flags, because this mode is only used for generate MakeFiles. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305561 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 6d3dbb5b52..bd4e894d65 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -980,6 +980,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, DepTarget = Args.MakeArgString(llvm::sys::path::filename(P)); } + if (!A->getOption().matches(options::OPT_MD) && !A->getOption().matches(options::OPT_MMD)) { + CmdArgs.push_back("-w"); + } CmdArgs.push_back("-MT"); SmallString<128> Quoted; QuoteTarget(DepTarget, Quoted); diff --git a/test/Driver/m_and_mm.c b/test/Driver/m_and_mm.c index 18cf7abfa6..e4d59bc70e 100644 --- a/test/Driver/m_and_mm.c +++ b/test/Driver/m_and_mm.c @@ -1,3 +1,15 @@ // RUN: %clang -### \ // RUN: -M -MM %s 2> %t // RUN: not grep '"-sys-header-deps"' %t + +// RUN: %clang -M -MM %s 2> %t +// RUN: not grep "warning" %t + +// RUN: %clang -MMD -MD %s 2> %t +// RUN: grep "warning" %t + +#warning "This warning shouldn't show up with -M and -MM" +int main (void) +{ + return 0; +}