Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1200,8 +1200,16 @@ llvm_unreachable("Invalid ABI kind for return argument"); } - if (RetTy->isReferenceType()) + if (RetTy->isReferenceType()) { + QualType PTy = RetTy->getAs()->getPointeeType(); + if (PTy->isConstantSizeType()) { + unsigned Bytes = + std::min(4095u, (unsigned) getContext().getTypeSize(PTy)/8); + RetAttrs.addDereferencableAttr(Bytes); + } + RetAttrs.addAttribute(llvm::Attribute::NonNull); + } if (RetAttrs.hasAttributes()) PAL.push_back(llvm:: @@ -1291,8 +1299,16 @@ } } - if (ParamType->isReferenceType()) + if (ParamType->isReferenceType()) { + QualType PTy = ParamType->getAs()->getPointeeType(); + if (PTy->isConstantSizeType()) { + unsigned Bytes = + std::min(4095u, (unsigned) getContext().getTypeSize(PTy)/8); + Attrs.addDereferencableAttr(Bytes); + } + Attrs.addAttribute(llvm::Attribute::NonNull); + } if (Attrs.hasAttributes()) PAL.push_back(llvm::AttributeSet::get(getLLVMContext(), Index, Attrs));