Index: clang/include/clang/Basic/DiagnosticIDs.h =================================================================== --- clang/include/clang/Basic/DiagnosticIDs.h +++ clang/include/clang/Basic/DiagnosticIDs.h @@ -263,6 +263,8 @@ /// are not SFINAE errors. static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID); + static std::vector getDiagnosticFlags(); + /// \brief Get the set of all diagnostic IDs in the group with the given name. /// /// \param[out] Diags - On return, the diagnostics in the group. Index: clang/lib/Basic/DiagnosticIDs.cpp =================================================================== --- clang/lib/Basic/DiagnosticIDs.cpp +++ clang/lib/Basic/DiagnosticIDs.cpp @@ -510,6 +510,21 @@ return StringRef(); } +std::vector DiagnosticIDs::getDiagnosticFlags() { + std::vector res; + for (int i = 1; DiagGroupNames[i] != '\0';) { + std::string Diag = + std::string(StringRef(DiagGroupNames + i + 1, DiagGroupNames[i])); + i += DiagGroupNames[i] + 1; + std::string W = "-W" + Diag; + std::string Wno = "-Wno" + Diag; + res.push_back(W); + res.push_back(Wno); + } + + return res; +} + /// Return \c true if any diagnostics were found in this group, even if they /// were filtered out due to having the wrong flavor. static bool getDiagnosticsInGroup(diag::Flavor Flavor, Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -1275,6 +1275,10 @@ // we were requested to print out all option names that start with "-foo". // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only". SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags); + + for (std::string S : DiagnosticIDs::getDiagnosticFlags()) + if (StringRef(S).startswith(PassedFlags)) + SuggestedCompletions.push_back(S); } else { // If the flag is in the form of "--autocomplete=foo,bar", we were // requested to print out all option values for "-foo" that start with Index: clang/test/Driver/autocomplete.c =================================================================== --- clang/test/Driver/autocomplete.c +++ clang/test/Driver/autocomplete.c @@ -40,3 +40,7 @@ // MRELOCMODEL_CLANG-NOT: -mrelocation-model // RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1 // MRELOCMODEL_CC1: -mrelocation-model +// RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING +// WARNING: -Wmacro-redefined -Wmain -Wmain-return-type -Wmalformed-warning-check -Wmany-braces-around-scalar-init -Wmax-unsigned-zero +// RUN: %clang --autocomplete=-Wnoinvalid-pp- | FileCheck %s -check-prefix=NOWARNING +// NOWARNING: -Wnoinvalid-pp-token