================ @@ -2799,9 +2799,37 @@ CodeGenFunction::EmitLoadOfReference(LValue RefLVal, llvm::LoadInst *Load = Builder.CreateLoad(RefLVal.getAddress(), RefLVal.isVolatile()); CGM.DecorateInstructionWithTBAA(Load, RefLVal.getTBAAInfo()); - return makeNaturalAddressForPointer(Load, RefLVal.getType()->getPointeeType(), - CharUnits(), /*ForPointeeType=*/true, - PointeeBaseInfo, PointeeTBAAInfo); + QualType PTy = RefLVal.getType()->getPointeeType(); + if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) { + llvm::LLVMContext &Ctx = getLLVMContext(); + llvm::MDBuilder MDB(Ctx); + // Emit !dereferenceable metadata + Load->setMetadata( + llvm::LLVMContext::MD_dereferenceable, + llvm::MDNode::get(Ctx, + MDB.createConstant(llvm::ConstantInt::get( + Builder.getInt64Ty(), ---------------- dtcxzyw wrote:
See https://eel.is/c++draft/dcl.ref#4 > 9.3.4.3 References > ... > It is unspecified whether or not a reference requires storage Does this statement mean a reference may not be dereferenceable? > This problem also exists for function parameters, but I think it's much more > likely to cause issues in this context. I copied this logic from function parameters. https://github.com/llvm/llvm-project/pull/98746 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits