From d32cc150feb72f315a5bbd34f92e7beca21a50da Mon Sep 17 00:00:00 2001 From: Daniil Suchkov Date: Fri, 4 Jun 2021 23:17:02 +0000 Subject: [PATCH] [BasicAA] Handle PHIs without incoming values gracefully Fix a bug introduced by f6f6f6375d1a4bced8a6e79a78726ab32b8dd879. Now for empty PHIs, instead of crashing on assert(hasVal()) in Optional's internals, we'll return NoAlias, as we did before that patch. Differential Revision: https://reviews.llvm.org/D103831 --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 2 ++ llvm/test/Transforms/JumpThreading/aa-crash-phi-no-args.ll | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index dec7fcb..356259f 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1293,6 +1293,8 @@ BasicAAResult::aliasSelect(const SelectInst *SI, LocationSize SISize, AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize, const Value *V2, LocationSize V2Size, AAQueryInfo &AAQI) { + if (!PN->getNumIncomingValues()) + return AliasResult::NoAlias; // If the values are PHIs in the same block, we can do a more precise // as well as efficient check: just check for aliases between the values // on corresponding edges. diff --git a/llvm/test/Transforms/JumpThreading/aa-crash-phi-no-args.ll b/llvm/test/Transforms/JumpThreading/aa-crash-phi-no-args.ll index 10de852..5bcd001 100644 --- a/llvm/test/Transforms/JumpThreading/aa-crash-phi-no-args.ll +++ b/llvm/test/Transforms/JumpThreading/aa-crash-phi-no-args.ll @@ -1,4 +1,3 @@ -; XFAIL: * ; REQUIRES: asserts ; RUN: opt -jump-threading -aa-pipeline basic-aa -S -disable-output %s ; RUN: opt -passes=jump-threading -aa-pipeline basic-aa -S -disable-output %s -- 2.7.4