Skip to content

Commit ca3121b

Browse files
authored
[Clang][Driver] Fix condition in combineBackendCompile when using -no-integrated-cpp (#136853)
When using -no-integrated-cpp, before, the driver won't collapse actions when the input was not llvm-ir or it would collapse them too aggressively with -save-temps The original code was checking the action type (which is IR too for preprocessed->bc actions) instead of the action inputs.
1 parent 47ce75e commit ca3121b

File tree

2 files changed

+93
-9
lines changed

2 files changed

+93
-9
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,19 +5612,20 @@ class ToolSelector final {
56125612
if (!BJ || !CJ)
56135613
return nullptr;
56145614

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

56305631
// Get compiler tool.
@@ -5638,7 +5639,7 @@ class ToolSelector final {
56385639
if (!T->hasIntegratedBackend() && !(OutputIsLLVM && T->canEmitIR()))
56395640
return nullptr;
56405641

5641-
if (T->canEmitIR() && ((SaveTemps && !InputIsBitcode) || EmbedBitcode))
5642+
if (T->canEmitIR() && EmbedBitcode)
56425643
return nullptr;
56435644

56445645
Inputs = CJ->getInputs();

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %clang -O2 %s -E -o %t.i
2+
//
3+
// RUN: %clang -O2 %s -c -o a.o -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=SRC
4+
// SRC: "-E"
5+
// SRC-SAME: "-o" "[[PREPROC:.*.i]]"
6+
// SRC-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
7+
//
8+
// SRC-NEXT: "-emit-obj"
9+
// SRC-SAME: "-o" "a.o"
10+
// SRC-SAME: "-x" "cpp-output" "[[PREPROC]]"
11+
//
12+
// RUN: %clang -O2 %s -c -o a.o -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=SRC-SAVE
13+
// SRC-SAVE: "-E"
14+
// SRC-SAVE-SAME: "-o" "[[PREPROC:.*.i]]"
15+
// SRC-SAVE-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
16+
//
17+
// SRC-SAVE-NEXT: "-emit-llvm-bc"
18+
// SRC-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
19+
// SRC-SAVE-SAME: "-x" "cpp-output" "[[PREPROC]]"
20+
//
21+
// SRC-SAVE-NEXT: "-S"
22+
// SRC-SAVE-SAME: "-o" "[[ASM:.*.s]]"
23+
// SRC-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
24+
//
25+
// SRC-SAVE-NEXT: "-cc1as"
26+
// SRC-SAVE-SAME: "-o" "a.o" "[[ASM]]"
27+
//
28+
// RUN: %clang -O2 %t.i -c -o a.o -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=PRE
29+
// PRE-NOT: "-E"
30+
// PRE: "-emit-obj"
31+
// PRE-SAME: "-o" "a.o"
32+
// PRE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
33+
//
34+
// RUN: %clang -O2 %t.i -c -o a.o -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=PRE-SAVE
35+
// PRE-SAVE-NOT: "-E"
36+
// PRE-SAVE: "-emit-llvm-bc"
37+
// PRE-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
38+
// PRE-SAVE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
39+
//
40+
// PRE-SAVE-NEXT: "-S"
41+
// PRE-SAVE-SAME: "-o" "[[ASM:.*.s]]"
42+
// PRE-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
43+
//
44+
// PRE-SAVE-NEXT: "-cc1as"
45+
// PRE-SAVE-SAME: "-o" "a.o" "[[ASM]]"
46+
//
47+
// RUN: %clang -O2 %s -c -emit-llvm -o a.bc -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=LLVM
48+
// LLVM: "-E"
49+
// LLVM-SAME: "-o" "[[PREPROC:.*.i]]"
50+
// LLVM-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
51+
//
52+
// LLVM-NEXT: "-emit-llvm-bc"
53+
// LLVM-SAME: "-o" "a.bc"
54+
// LLVM-SAME: "-x" "cpp-output" "[[PREPROC]]"
55+
//
56+
// RUN: %clang -O2 %s -c -emit-llvm -o a.bc -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=LLVM-SAVE
57+
// LLVM-SAVE: "-E"
58+
// LLVM-SAVE-SAME: "-o" "[[PREPROC:.*.i]]"
59+
// LLVM-SAVE-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
60+
//
61+
// LLVM-SAVE-NEXT: "-emit-llvm-bc"
62+
// LLVM-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
63+
// LLVM-SAVE-SAME: "-x" "cpp-output" "[[PREPROC]]"
64+
//
65+
// LLVM-SAVE-NEXT: "-emit-llvm-bc"
66+
// LLVM-SAVE-SAME: "-o" "a.bc"
67+
// LLVM-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
68+
//
69+
// RUN: %clang -O2 %t.i -c -emit-llvm -o a.bc -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=PRE-LLVM
70+
// PRE-LLVM-NOT: "-E"
71+
// PRE-LLVM: "-emit-llvm-bc"
72+
// PRE-LLVM-SAME: "-o" "a.bc"
73+
// PRE-LLVM-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
74+
//
75+
// 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
76+
// PRE-LLVM-SAVE-NOT: "-E"
77+
// PRE-LLVM-SAVE: "-emit-llvm-bc"
78+
// PRE-LLVM-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
79+
// 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)