Skip to content

Commit ddbd409

Browse files
committed
[Clang][Driver] Fix condition in combineBackendCompile when using -no-integrated-cpp
When using -no-integrated-cpp, before, the driver won't collapse actions when the input was not llvm-ir or it would collapse them aggresively with -save-temps
1 parent 1acf00c commit ddbd409

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

clang/lib/Driver/Driver.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -5609,19 +5609,20 @@ class ToolSelector final {
56095609
if (!BJ || !CJ)
56105610
return nullptr;
56115611

5612+
auto HasBitcodeInput = [](const JobActionInfo &AI) {
5613+
for (auto &Input : AI.JA->getInputs())
5614+
if (!types::isLLVMIR(Input->getType()))
5615+
return false;
5616+
return true;
5617+
};
5618+
56125619
// Check if the initial input (to the compile job or its predessor if one
56135620
// exists) is LLVM bitcode. In that case, no preprocessor step is required
56145621
// and we can still collapse the compile and backend jobs when we have
56155622
// -save-temps. I.e. there is no need for a separate compile job just to
56165623
// emit unoptimized bitcode.
5617-
bool InputIsBitcode = true;
5618-
for (size_t i = 1; i < ActionInfo.size(); i++)
5619-
if (ActionInfo[i].JA->getType() != types::TY_LLVM_BC &&
5620-
ActionInfo[i].JA->getType() != types::TY_LTO_BC) {
5621-
InputIsBitcode = false;
5622-
break;
5623-
}
5624-
if (!InputIsBitcode && !canCollapsePreprocessorAction())
5624+
bool InputIsBitcode = all_of(ActionInfo, HasBitcodeInput);
5625+
if (SaveTemps && !InputIsBitcode)
56255626
return nullptr;
56265627

56275628
// Get compiler tool.
@@ -5635,7 +5636,7 @@ class ToolSelector final {
56355636
if (!T->hasIntegratedBackend() && !(OutputIsLLVM && T->canEmitIR()))
56365637
return nullptr;
56375638

5638-
if (T->canEmitIR() && ((SaveTemps && !InputIsBitcode) || EmbedBitcode))
5639+
if (T->canEmitIR() && EmbedBitcode)
56395640
return nullptr;
56405641

56415642
Inputs = CJ->getInputs();

clang/test/Driver/no-integrated-cpp.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
//
3434
// RUN: %clang -O2 %t.i -c -o a.o -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=PRE-SAVE
3535
// PRE-SAVE-NOT: "-E"
36-
// PRE-SAVE-NOT: "-emit-llvm-bc"
37-
// PRE-SAVE: "-S"
38-
// PRE-SAVE-SAME: "-o" "[[ASM:.*.s]]"
36+
// PRE-SAVE: "-emit-llvm-bc"
37+
// PRE-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
3938
// PRE-SAVE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
4039
//
40+
// PRE-SAVE-NEXT: "-S"
41+
// PRE-SAVE-SAME: "-o" "[[ASM:.*.s]]"
42+
// PRE-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
43+
//
4144
// PRE-SAVE-NEXT: "-cc1as"
4245
// PRE-SAVE-SAME: "-o" "a.o" "[[ASM]]"
4346
//
@@ -47,12 +50,8 @@
4750
// LLVM-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
4851
//
4952
// LLVM-NEXT: "-emit-llvm-bc"
50-
// LLVM-SAME: "-o" "[[BITCODE:.*.bc]]"
51-
// LLVM-SAME: "-x" "cpp-output" "[[PREPROC]]"
52-
//
53-
// LLVM-NEXT: "-emit-llvm-bc"
5453
// LLVM-SAME: "-o" "a.bc"
55-
// LLVM-SAME: "-x" "ir" "[[BITCODE]]"
54+
// LLVM-SAME: "-x" "cpp-output" "[[PREPROC]]"
5655
//
5756
// RUN: %clang -O2 %s -c -emit-llvm -o a.bc -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=LLVM-SAVE
5857
// LLVM-SAVE: "-E"
@@ -76,5 +75,9 @@
7675
// RUN: %clang -O2 %t.i -c -emit-llvm -o a.bc -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=PRE-LLVM-SAVE
7776
// PRE-LLVM-SAVE-NOT: "-E"
7877
// PRE-LLVM-SAVE: "-emit-llvm-bc"
79-
// PRE-LLVM-SAVE-SAME: "-o" "a.bc"
78+
// PRE-LLVM-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
8079
// PRE-LLVM-SAVE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
80+
81+
// PRE-LLVM-SAVE-NEXT: "-emit-llvm-bc"
82+
// PRE-LLVM-SAVE-SAME: "-o" "a.bc"
83+
// PRE-LLVM-SAVE-SAME: "-x" "ir" "[[BITCODE]]"

0 commit comments

Comments
 (0)