https://github.com/macurtis-amd updated https://github.com/llvm/llvm-project/pull/134621
>From 9d38a08bc91273d961fa1bd855d212b09249d826 Mon Sep 17 00:00:00 2001 From: Matthew Curtis <macur...@amd.com> Date: Fri, 18 Apr 2025 12:46:23 -0500 Subject: [PATCH] [clang] Suppress gnu-line-marker when saving temps When passing `-save-temps` to clang, the generated preprocessed output uses gnu line markers. This unexpectedly triggers gnu-line-marker warnings when used with `-Weverything` or `-pedantic`. Even worse, compilation fails if `-Werror` is used. This change suppresses gnu-line-marker warnings when invoking 'clang' with preprocessor input (specified via -x argument or deduced from the input file name). This matches gcc behavior. fixes #63802 --- clang/lib/Frontend/InitPreprocessor.cpp | 8 ++++++++ clang/test/Preprocessor/line-directive-suppressed.c | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 clang/test/Preprocessor/line-directive-suppressed.c diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 1f297f228fc1b..5d32eeb5f3b28 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/DiagnosticLex.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/HLSLRuntime.h" #include "clang/Basic/MacroBuilder.h" @@ -1643,4 +1644,11 @@ void clang::InitializePreprocessor(Preprocessor &PP, // Copy PredefinedBuffer into the Preprocessor. PP.setPredefines(std::move(PredefineBuffer)); + + // Match gcc behavior regarding gnu-line-directive diagnostics, assuming that + // '-x <*>-cpp-output' is analogous to '-fpreprocessed'. + if (FEOpts.DashX.isPreprocessed()) { + PP.getDiagnostics().setSeverity(diag::ext_pp_gnu_line_directive, + diag::Severity::Ignored, SourceLocation()); + } } diff --git a/clang/test/Preprocessor/line-directive-suppressed.c b/clang/test/Preprocessor/line-directive-suppressed.c new file mode 100644 index 0000000000000..db97f211c28f4 --- /dev/null +++ b/clang/test/Preprocessor/line-directive-suppressed.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %s 2>&1 | grep 'warning: this style of line directive is a GNU extension' + +// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -x c-cpp-output %s 2>&1 | not grep warning +// RUN: cp %s %t.i +// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %t.i 2>&1 | not grep warning + +# 0 "zero" +# 1 "one" 1 +# 2 "two" 1 3 4 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits