Skip to content

Commit

Permalink
Fix for bug 38508 - Don't do PCH processing when only generating prep…
Browse files Browse the repository at this point in the history
…rocessor output

This clang-cl driver change removes the PCH options when we are only generating
preprocessed output. This is similar to the behavior of Y-.

Patch by: mikerice
Differential Revision: https://reviews.llvm.org/D50640

llvm-svn: 340025
  • Loading branch information
Erich Keane committed Aug 17, 2018
1 parent 734a04e commit eaca388
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clang/lib/Driver/Driver.cpp
Expand Up @@ -3010,9 +3010,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
Args.eraseArg(options::OPT__SLASH_Yc);
YcArg = nullptr;
}
if (Args.hasArg(options::OPT__SLASH_Y_)) {
// /Y- disables all pch handling. Rather than check for it everywhere,
// just remove clang-cl pch-related flags here.
if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) {
// If only preprocessing or /Y- is used, all pch handling is disabled.
// Rather than check for it everywhere, just remove clang-cl pch-related
// flags here.
Args.eraseArg(options::OPT__SLASH_Fp);
Args.eraseArg(options::OPT__SLASH_Yc);
Args.eraseArg(options::OPT__SLASH_Yu);
Expand Down
21 changes: 21 additions & 0 deletions clang/test/Driver/cl-pch.cpp
Expand Up @@ -345,3 +345,24 @@
// CHECK-NoSourceTP: pchfile.pch
// CHECK-NoSourceTP: -x
// CHECK-NoSourceTP: "c++"

// If only preprocessing, PCH options are ignored.
// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-YC-P %s
// CHECK-YC-P-NOT: -emit-pch
// CHECK-YC-P-NOT: -include-pch

// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-YC-E %s
// CHECK-YC-E-NOT: -emit-pch
// CHECK-YC-E-NOT: -include-pch

// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-YU-P %s
// CHECK-YU-P-NOT: -emit-pch
// CHECK-YU-P-NOT: -include-pch

// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-YU-E %s
// CHECK-YU-E-NOT: -emit-pch
// CHECK-YU-E-NOT: -include-pch
2 changes: 2 additions & 0 deletions clang/test/PCH/Inputs/pch-through-use3c.cpp
@@ -0,0 +1,2 @@
int a = A;
// expected-no-diagnostics
1 change: 1 addition & 0 deletions clang/test/PCH/Inputs/pch-through3c.h
@@ -0,0 +1 @@
#define A 1
8 changes: 8 additions & 0 deletions clang/test/PCH/pch-through3c.cpp
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -I %S -emit-pch \
// RUN: -include Inputs/pch-through3c.h \
// RUN: -pch-through-header=Inputs/pch-through3c.h -o %t.3c %s

// RUN: %clang_cc1 -verify -I %S -include-pch %t.3c \
// RUN: -include Inputs/pch-through3c.h \
// RUN: -pch-through-header=Inputs/pch-through3c.h \
// RUN: %S/Inputs/pch-through-use3c.cpp 2>&1

0 comments on commit eaca388

Please sign in to comment.