From 20c873c12fa5563bbfb07c880db51fa68db571cc Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Tue, 19 Apr 2022 15:55:01 -0700 Subject: [PATCH] [PS5] Avoid a driver crash In some cases, an error constructing a compiler or assembler job could leave the Inputs in a state that the code for constructing the linker job was not ready for. --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 4 ++++ clang/test/Driver/no-integrated-as.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 1207bf37b5bb..96a54228626f 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -255,6 +255,10 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, continue; } + // In some error cases, the input could be Nothing; skip those. + if (II.isNothing()) + continue; + // Otherwise, this is a linker input argument. const Arg &A = II.getInputArg(); diff --git a/clang/test/Driver/no-integrated-as.c b/clang/test/Driver/no-integrated-as.c index 6f45a6050e9f..617e319764ef 100644 --- a/clang/test/Driver/no-integrated-as.c +++ b/clang/test/Driver/no-integrated-as.c @@ -13,8 +13,9 @@ // DEFAULT-NOT: -no-integrated-as -// RUN: %clang -target x86_64-sie-ps5 -### -no-integrated-as %s -c 2>&1 \ +/// -c omitted on purpose, this used to crash. +// RUN: %clang -target x86_64-sie-ps5 -### -no-integrated-as %s 2>&1 \ // RUN: | FileCheck %s -check-prefix PS5 -// RUN: %clang -target x86_64-sie-ps5 -### -no-integrated-as %s -c -x assembler 2>&1 \ +// RUN: %clang -target x86_64-sie-ps5 -### -no-integrated-as %s -x assembler 2>&1 \ // RUN: | FileCheck %s -check-prefix PS5 // PS5: there is no external assembler that can be used on this platform