llvm.org GIT mirror llvm / 1bd4284
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275532 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
2 changed file(s) with 17 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
231231 if (auto *FP = dyn_cast(V))
232232 if (isa(this))
233233 copyFastMathFlags(FP->getFastMathFlags());
234
235 if (auto *SrcGEP = dyn_cast(V))
236 if (auto *DestGEP = dyn_cast(this))
237 DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
234238 }
235239
236240 void Instruction::andIRFlags(const Value *V) {
252256 copyFastMathFlags(FM);
253257 }
254258 }
259
260 if (auto *SrcGEP = dyn_cast(V))
261 if (auto *DestGEP = dyn_cast(this))
262 DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
255263 }
256264
257265 const char *Instruction::getOpcodeName(unsigned OpCode) {
0 ; RUN: opt -S -gvn < %s | FileCheck %s
1 define i32* @test1(i32* %a) {
2 %x1 = getelementptr inbounds i32, i32* %a, i32 10
3 %x2 = getelementptr i32, i32* %a, i32 10
4 ret i32* %x2
5 ; CHECK-LABEL: @test1(
6 ; CHECK: %[[x:.*]] = getelementptr i32, i32* %a, i32 10
7 ; CHECK: ret i32* %[[x]]
8 }