mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-29 22:30:33 +00:00
[IR] andIRFlags and copyIRFlags needs to handle GEP
We didn't consider the inbounds flag on GEPs leading to downstream users introducing UB. This fixes PR28562. llvm-svn: 275532
This commit is contained in:
parent
de4821c537
commit
f7d30cf67a
@ -232,6 +232,10 @@ void Instruction::copyIRFlags(const Value *V) {
|
||||
if (auto *FP = dyn_cast<FPMathOperator>(V))
|
||||
if (isa<FPMathOperator>(this))
|
||||
copyFastMathFlags(FP->getFastMathFlags());
|
||||
|
||||
if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
|
||||
if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
|
||||
DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
|
||||
}
|
||||
|
||||
void Instruction::andIRFlags(const Value *V) {
|
||||
@ -253,6 +257,10 @@ void Instruction::andIRFlags(const Value *V) {
|
||||
copyFastMathFlags(FM);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
|
||||
if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
|
||||
DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
|
||||
}
|
||||
|
||||
const char *Instruction::getOpcodeName(unsigned OpCode) {
|
||||
|
9
test/Transforms/GVN/pr28562.ll
Normal file
9
test/Transforms/GVN/pr28562.ll
Normal file
@ -0,0 +1,9 @@
|
||||
; RUN: opt -S -gvn < %s | FileCheck %s
|
||||
define i32* @test1(i32* %a) {
|
||||
%x1 = getelementptr inbounds i32, i32* %a, i32 10
|
||||
%x2 = getelementptr i32, i32* %a, i32 10
|
||||
ret i32* %x2
|
||||
; CHECK-LABEL: @test1(
|
||||
; CHECK: %[[x:.*]] = getelementptr i32, i32* %a, i32 10
|
||||
; CHECK: ret i32* %[[x]]
|
||||
}
|
Loading…
Reference in New Issue
Block a user