rsmith added a subscriber: rsmith. ================ Comment at: lib/CodeGen/CGDecl.cpp:933 @@ +932,3 @@ + ASTContext &Ctx = getContext(); + auto &OffsetsInfo = InvariantOffsets.FindAndConstruct(Record).second; + OffsetsType &Args = OffsetsInfo.Offsets; ---------------- Instead of tracking a separate `Computed` flag, use `InvariantOffsets.count(Record)` here, and insert the value below.
================ Comment at: lib/CodeGen/CGDecl.cpp:943-959 @@ -950,2 +942,19 @@ + + // Trace through fields collecting offsets of writeonce candidates. + for (const auto *Field : Record->fields()) { + assert(dyn_cast<FieldDecl>(Field) && "Field decls only."); + QualType FieldType = Field->getType(); + if (FieldType.isWriteOnce(Ctx)) { + CharUnits WidthChars = Ctx.getTypeSizeInChars(FieldType); + uint64_t Width = WidthChars.getQuantity(); + Args.push_back(llvm::ConstantInt::get(Int64Ty, Width)); // Size + + uint64_t Offset = Ctx.getFieldOffset(Field); + Args.push_back(llvm::ConstantInt::get(Int64Ty, Offset)); // Offset + } else if (const CXXRecordDecl *RecField = + Ctx.getBaseElementType(FieldType)->getAsCXXRecordDecl()) { + auto &FieldArgs = ComputeInvariantOffsets(RecField); + Args.insert(Args.end(), FieldArgs.begin(), FieldArgs.end()); } } + ---------------- It'd be good to also handle the case of a `const` field of class type that contains a `mutable` member -- in that case, all members other than the `mutable` member can be marked as invariant. ================ Comment at: lib/CodeGen/CGDecl.cpp:956-957 @@ -950,1 +955,4 @@ + Ctx.getBaseElementType(FieldType)->getAsCXXRecordDecl()) { + auto &FieldArgs = ComputeInvariantOffsets(RecField); + Args.insert(Args.end(), FieldArgs.begin(), FieldArgs.end()); } ---------------- The recursive call to `ComputeInvariatOffsets` here invalidates your `Args` reference (`DenseMap` insertions invalidate all iterators and references to map elements). http://reviews.llvm.org/D13618 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits