Skip to content

[Clang][Driver] Fix condition in combineBackendCompile when using -no-integrated-cpp #136853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5609,19 +5609,20 @@ class ToolSelector final {
if (!BJ || !CJ)
return nullptr;

auto HasBitcodeInput = [](const JobActionInfo &AI) {
for (auto &Input : AI.JA->getInputs())
if (!types::isLLVMIR(Input->getType()))
return false;
return true;
};

// Check if the initial input (to the compile job or its predessor if one
// exists) is LLVM bitcode. In that case, no preprocessor step is required
// and we can still collapse the compile and backend jobs when we have
// -save-temps. I.e. there is no need for a separate compile job just to
// emit unoptimized bitcode.
bool InputIsBitcode = true;
for (size_t i = 1; i < ActionInfo.size(); i++)
if (ActionInfo[i].JA->getType() != types::TY_LLVM_BC &&
ActionInfo[i].JA->getType() != types::TY_LTO_BC) {
InputIsBitcode = false;
break;
}
if (!InputIsBitcode && !canCollapsePreprocessorAction())
bool InputIsBitcode = all_of(ActionInfo, HasBitcodeInput);
if (SaveTemps && !InputIsBitcode)
return nullptr;

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

if (T->canEmitIR() && ((SaveTemps && !InputIsBitcode) || EmbedBitcode))
if (T->canEmitIR() && EmbedBitcode)
return nullptr;

Inputs = CJ->getInputs();
Expand Down
83 changes: 83 additions & 0 deletions clang/test/Driver/no-integrated-cpp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// RUN: %clang -O2 %s -E -o %t.i
//
// RUN: %clang -O2 %s -c -o a.o -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=SRC
// SRC: "-E"
// SRC-SAME: "-o" "[[PREPROC:.*.i]]"
// SRC-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
//
// SRC-NEXT: "-emit-obj"
// SRC-SAME: "-o" "a.o"
// SRC-SAME: "-x" "cpp-output" "[[PREPROC]]"
//
// RUN: %clang -O2 %s -c -o a.o -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=SRC-SAVE
// SRC-SAVE: "-E"
// SRC-SAVE-SAME: "-o" "[[PREPROC:.*.i]]"
// SRC-SAVE-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
//
// SRC-SAVE-NEXT: "-emit-llvm-bc"
// SRC-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
// SRC-SAVE-SAME: "-x" "cpp-output" "[[PREPROC]]"
//
// SRC-SAVE-NEXT: "-S"
// SRC-SAVE-SAME: "-o" "[[ASM:.*.s]]"
// SRC-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
//
// SRC-SAVE-NEXT: "-cc1as"
// SRC-SAVE-SAME: "-o" "a.o" "[[ASM]]"
//
// RUN: %clang -O2 %t.i -c -o a.o -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=PRE
// PRE-NOT: "-E"
// PRE: "-emit-obj"
// PRE-SAME: "-o" "a.o"
// PRE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
//
// RUN: %clang -O2 %t.i -c -o a.o -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=PRE-SAVE
// PRE-SAVE-NOT: "-E"
// PRE-SAVE: "-emit-llvm-bc"
// PRE-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
// PRE-SAVE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
//
// PRE-SAVE-NEXT: "-S"
// PRE-SAVE-SAME: "-o" "[[ASM:.*.s]]"
// PRE-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
//
// PRE-SAVE-NEXT: "-cc1as"
// PRE-SAVE-SAME: "-o" "a.o" "[[ASM]]"
//
// RUN: %clang -O2 %s -c -emit-llvm -o a.bc -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=LLVM
// LLVM: "-E"
// LLVM-SAME: "-o" "[[PREPROC:.*.i]]"
// LLVM-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
//
// LLVM-NEXT: "-emit-llvm-bc"
// LLVM-SAME: "-o" "a.bc"
// LLVM-SAME: "-x" "cpp-output" "[[PREPROC]]"
//
// RUN: %clang -O2 %s -c -emit-llvm -o a.bc -no-integrated-cpp -save-temps -### 2>&1 | FileCheck %s --check-prefixes=LLVM-SAVE
// LLVM-SAVE: "-E"
// LLVM-SAVE-SAME: "-o" "[[PREPROC:.*.i]]"
// LLVM-SAVE-SAME: "-x" "c" "{{.*}}no-integrated-cpp.c"
//
// LLVM-SAVE-NEXT: "-emit-llvm-bc"
// LLVM-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
// LLVM-SAVE-SAME: "-x" "cpp-output" "[[PREPROC]]"
//
// LLVM-SAVE-NEXT: "-emit-llvm-bc"
// LLVM-SAVE-SAME: "-o" "a.bc"
// LLVM-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
//
// RUN: %clang -O2 %t.i -c -emit-llvm -o a.bc -no-integrated-cpp -### 2>&1 | FileCheck %s --check-prefixes=PRE-LLVM
// PRE-LLVM-NOT: "-E"
// PRE-LLVM: "-emit-llvm-bc"
// PRE-LLVM-SAME: "-o" "a.bc"
// PRE-LLVM-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"
//
// 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
// PRE-LLVM-SAVE-NOT: "-E"
// PRE-LLVM-SAVE: "-emit-llvm-bc"
// PRE-LLVM-SAVE-SAME: "-o" "[[BITCODE:.*.bc]]"
// PRE-LLVM-SAVE-SAME: "-x" "cpp-output" "{{.*}}no-integrated-cpp.c.tmp.i"

// PRE-LLVM-SAVE-NEXT: "-emit-llvm-bc"
// PRE-LLVM-SAVE-SAME: "-o" "a.bc"
// PRE-LLVM-SAVE-SAME: "-x" "ir" "[[BITCODE]]"
Loading