Skip to content

Commit 73d6be6

Browse files
macurtis-amdtomtor
authored andcommitted
[clang][driver] Suppress gnu-line-marker when saving temps (llvm#134621)
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 input from a preprocessor job and the user has not otherwise explictly specified `-Wgnu-line-marker` somewhere on the command line. Note that this does apply to user provided preprocessed files. fixes llvm#63802
1 parent 0a1c3b2 commit 73d6be6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
2+
3+
// RUN: cp %s %t.i
4+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic %t.i 2>&1 | FileCheck %s --check-prefix=NO-WARNING --allow-empty
5+
// RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -x cpp-output %s 2>&1 | FileCheck %s --check-prefix=NO-WARNING --allow-empty
6+
7+
# 0 "zero"
8+
// CHECK: line-directive-suppressed.c:[[@LINE-1]]:5: warning: {{.*}} [-Wgnu-line-marker]
9+
10+
# 1 "one" 1
11+
// CHECK: zero:2:5: warning: {{.*}} [-Wgnu-line-marker]
12+
13+
# 2 "two" 1 3 4
14+
// CHECK: one:3:5: warning: {{.*}} [-Wgnu-line-marker]
15+
16+
// NO-WARNING-NOT: warning:

0 commit comments

Comments
 (0)