llvm.org GIT mirror llvm / 5e1d0d3
fix PR17635: false positive with packed structures LLVM optimizers may widen accesses to packed structures that overflow the structure itself, but should be in bounds up to the alignment of the object git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193317 91177308-0d34-0410-b5e6-96231b3b80d8 Nuno Lopes 7 years ago
4 changed file(s) with 38 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
227227 Value *Zero;
228228 CacheMapTy CacheMap;
229229 PtrSetTy SeenVals;
230 bool RoundToAlign;
230231
231232 SizeOffsetEvalType unknown() {
232233 return std::make_pair((Value*)0, (Value*)0);
235236
236237 public:
237238 ObjectSizeOffsetEvaluator(const DataLayout *DL, const TargetLibraryInfo *TLI,
238 LLVMContext &Context);
239 LLVMContext &Context, bool RoundToAlign = false);
239240 SizeOffsetEvalType compute(Value *V);
240241
241242 bool knownSize(SizeOffsetEvalType SizeOffset) {
587587
588588 ObjectSizeOffsetEvaluator::ObjectSizeOffsetEvaluator(const DataLayout *DL,
589589 const TargetLibraryInfo *TLI,
590 LLVMContext &Context)
591 : DL(DL), TLI(TLI), Context(Context), Builder(Context, TargetFolder(DL)) {
590 LLVMContext &Context,
591 bool RoundToAlign)
592 : DL(DL), TLI(TLI), Context(Context), Builder(Context, TargetFolder(DL)),
593 RoundToAlign(RoundToAlign) {
592594 IntTy = DL->getIntPtrType(Context);
593595 Zero = ConstantInt::get(IntTy, 0);
594596 }
613615 }
614616
615617 SizeOffsetEvalType ObjectSizeOffsetEvaluator::compute_(Value *V) {
616 ObjectSizeOffsetVisitor Visitor(DL, TLI, Context);
618 ObjectSizeOffsetVisitor Visitor(DL, TLI, Context, RoundToAlign);
617619 SizeOffsetType Const = Visitor.compute(V);
618620 if (Visitor.bothKnown(Const))
619621 return std::make_pair(ConstantInt::get(Context, Const.first),
171171 TrapBB = 0;
172172 BuilderTy TheBuilder(F.getContext(), TargetFolder(TD));
173173 Builder = &TheBuilder;
174 ObjectSizeOffsetEvaluator TheObjSizeEval(TD, TLI, F.getContext());
174 ObjectSizeOffsetEvaluator TheObjSizeEval(TD, TLI, F.getContext(),
175 /*RoundToAlign=*/true);
175176 ObjSizeEval = &TheObjSizeEval;
176177
177178 // check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory
0 ; RUN: opt < %s -bounds-checking -S | FileCheck %s
1
2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
3
4 %struct.s2_packed = type <{ i64, i32, i32, i32, i16, i8 }>
5
6 ; CHECK-LABEL: @f
7 ; CHECK-NOT: trap
8 define i16 @f() {
9 entry:
10 %packed1 = alloca %struct.s2_packed, align 8
11 %gep = getelementptr inbounds %struct.s2_packed* %packed1, i32 0, i32 4
12 %ptr = bitcast i16* %gep to i32*
13 %val = load i32* %ptr, align 4
14 %valt = trunc i32 %val to i16
15 ret i16 %valt
16 }
17
18 ; CHECK-LABEL: @f
19 ; CHECK: call void @llvm.trap()
20 define i16 @f2() {
21 entry:
22 %packed1 = alloca %struct.s2_packed, align 8
23 %gep = getelementptr inbounds %struct.s2_packed* %packed1, i32 0, i32 4
24 %ptr = bitcast i16* %gep to i48*
25 %val = load i48* %ptr, align 4
26 %valt = trunc i48 %val to i16
27 ret i16 %valt
28 }