Skip to content

Commit d78c113

Browse files
committed
[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
1 parent c400fe2 commit d78c113

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "clang/Basic/DiagnosticLex.h"
1314
#include "clang/Basic/HLSLRuntime.h"
1415
#include "clang/Basic/MacroBuilder.h"
1516
#include "clang/Basic/SourceManager.h"
@@ -1644,4 +1645,11 @@ void clang::InitializePreprocessor(Preprocessor &PP,
16441645

16451646
// Copy PredefinedBuffer into the Preprocessor.
16461647
PP.setPredefines(std::move(PredefineBuffer));
1648+
1649+
// Match gcc behavior regarding gnu-line-directive diagnostics, assuming that
1650+
// '-x <*>-cpp-output' is analogous to '-fpreprocessed'.
1651+
if (FEOpts.DashX.isPreprocessed()) {
1652+
PP.getDiagnostics().setSeverity(diag::ext_pp_gnu_line_directive,
1653+
diag::Severity::Ignored, SourceLocation());
1654+
}
16471655
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %s 2>&1 | grep 'warning: this style of line directive is a GNU extension'
2+
3+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -x c-cpp-output %s 2>&1 | not grep warning
4+
// RUN: cp %s %t.i
5+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %t.i 2>&1 | not grep warning
6+
7+
# 0 "zero"
8+
# 1 "one" 1
9+
# 2 "two" 1 3 4

0 commit comments

Comments
 (0)