Index: clang/include/clang/AST/APValue.h =================================================================== --- clang/include/clang/AST/APValue.h +++ clang/include/clang/AST/APValue.h @@ -402,7 +402,7 @@ APSInt &getInt() { assert(isInt() && "Invalid accessor"); - return *(APSInt*)(char*)Data.buffer; + return *(APSInt *)(char *)&Data; } const APSInt &getInt() const { return const_cast(this)->getInt(); @@ -416,7 +416,7 @@ APFloat &getFloat() { assert(isFloat() && "Invalid accessor"); - return *(APFloat*)(char*)Data.buffer; + return *(APFloat *)(char *)&Data; } const APFloat &getFloat() const { return const_cast(this)->getFloat(); @@ -424,7 +424,7 @@ APFixedPoint &getFixedPoint() { assert(isFixedPoint() && "Invalid accessor"); - return *(APFixedPoint *)(char *)Data.buffer; + return *(APFixedPoint *)(char *)&Data; } const APFixedPoint &getFixedPoint() const { return const_cast(this)->getFixedPoint(); @@ -432,7 +432,7 @@ APSInt &getComplexIntReal() { assert(isComplexInt() && "Invalid accessor"); - return ((ComplexAPSInt*)(char*)Data.buffer)->Real; + return ((ComplexAPSInt *)(char *)&Data)->Real; } const APSInt &getComplexIntReal() const { return const_cast(this)->getComplexIntReal(); @@ -440,7 +440,7 @@ APSInt &getComplexIntImag() { assert(isComplexInt() && "Invalid accessor"); - return ((ComplexAPSInt*)(char*)Data.buffer)->Imag; + return ((ComplexAPSInt *)(char *)&Data)->Imag; } const APSInt &getComplexIntImag() const { return const_cast(this)->getComplexIntImag(); @@ -448,7 +448,7 @@ APFloat &getComplexFloatReal() { assert(isComplexFloat() && "Invalid accessor"); - return ((ComplexAPFloat*)(char*)Data.buffer)->Real; + return ((ComplexAPFloat *)(char *)&Data)->Real; } const APFloat &getComplexFloatReal() const { return const_cast(this)->getComplexFloatReal(); @@ -456,7 +456,7 @@ APFloat &getComplexFloatImag() { assert(isComplexFloat() && "Invalid accessor"); - return ((ComplexAPFloat*)(char*)Data.buffer)->Imag; + return ((ComplexAPFloat *)(char *)&Data)->Imag; } const APFloat &getComplexFloatImag() const { return const_cast(this)->getComplexFloatImag(); @@ -477,20 +477,20 @@ APValue &getVectorElt(unsigned I) { assert(isVector() && "Invalid accessor"); assert(I < getVectorLength() && "Index out of range"); - return ((Vec*)(char*)Data.buffer)->Elts[I]; + return ((Vec *)(char *)&Data)->Elts[I]; } const APValue &getVectorElt(unsigned I) const { return const_cast(this)->getVectorElt(I); } unsigned getVectorLength() const { assert(isVector() && "Invalid accessor"); - return ((const Vec*)(const void *)Data.buffer)->NumElts; + return ((const Vec *)(const void *)&Data)->NumElts; } APValue &getArrayInitializedElt(unsigned I) { assert(isArray() && "Invalid accessor"); assert(I < getArrayInitializedElts() && "Index out of range"); - return ((Arr*)(char*)Data.buffer)->Elts[I]; + return ((Arr *)(char *)&Data)->Elts[I]; } const APValue &getArrayInitializedElt(unsigned I) const { return const_cast(this)->getArrayInitializedElt(I); @@ -501,35 +501,35 @@ APValue &getArrayFiller() { assert(isArray() && "Invalid accessor"); assert(hasArrayFiller() && "No array filler"); - return ((Arr*)(char*)Data.buffer)->Elts[getArrayInitializedElts()]; + return ((Arr *)(char *)&Data)->Elts[getArrayInitializedElts()]; } const APValue &getArrayFiller() const { return const_cast(this)->getArrayFiller(); } unsigned getArrayInitializedElts() const { assert(isArray() && "Invalid accessor"); - return ((const Arr*)(const void *)Data.buffer)->NumElts; + return ((const Arr *)(const void *)&Data)->NumElts; } unsigned getArraySize() const { assert(isArray() && "Invalid accessor"); - return ((const Arr*)(const void *)Data.buffer)->ArrSize; + return ((const Arr *)(const void *)&Data)->ArrSize; } unsigned getStructNumBases() const { assert(isStruct() && "Invalid accessor"); - return ((const StructData*)(const char*)Data.buffer)->NumBases; + return ((const StructData *)(const char *)&Data)->NumBases; } unsigned getStructNumFields() const { assert(isStruct() && "Invalid accessor"); - return ((const StructData*)(const char*)Data.buffer)->NumFields; + return ((const StructData *)(const char *)&Data)->NumFields; } APValue &getStructBase(unsigned i) { assert(isStruct() && "Invalid accessor"); - return ((StructData*)(char*)Data.buffer)->Elts[i]; + return ((StructData *)(char *)&Data)->Elts[i]; } APValue &getStructField(unsigned i) { assert(isStruct() && "Invalid accessor"); - return ((StructData*)(char*)Data.buffer)->Elts[getStructNumBases() + i]; + return ((StructData *)(char *)&Data)->Elts[getStructNumBases() + i]; } const APValue &getStructBase(unsigned i) const { return const_cast(this)->getStructBase(i); @@ -540,11 +540,11 @@ const FieldDecl *getUnionField() const { assert(isUnion() && "Invalid accessor"); - return ((const UnionData*)(const char*)Data.buffer)->Field; + return ((const UnionData *)(const char *)&Data)->Field; } APValue &getUnionValue() { assert(isUnion() && "Invalid accessor"); - return *((UnionData*)(char*)Data.buffer)->Value; + return *((UnionData *)(char *)&Data)->Value; } const APValue &getUnionValue() const { return const_cast(this)->getUnionValue(); @@ -556,24 +556,24 @@ const AddrLabelExpr* getAddrLabelDiffLHS() const { assert(isAddrLabelDiff() && "Invalid accessor"); - return ((const AddrLabelDiffData*)(const char*)Data.buffer)->LHSExpr; + return ((const AddrLabelDiffData *)(const char *)&Data)->LHSExpr; } const AddrLabelExpr* getAddrLabelDiffRHS() const { assert(isAddrLabelDiff() && "Invalid accessor"); - return ((const AddrLabelDiffData*)(const char*)Data.buffer)->RHSExpr; + return ((const AddrLabelDiffData *)(const char *)&Data)->RHSExpr; } void setInt(APSInt I) { assert(isInt() && "Invalid accessor"); - *(APSInt *)(char *)Data.buffer = std::move(I); + *(APSInt *)(char *)&Data = std::move(I); } void setFloat(APFloat F) { assert(isFloat() && "Invalid accessor"); - *(APFloat *)(char *)Data.buffer = std::move(F); + *(APFloat *)(char *)&Data = std::move(F); } void setFixedPoint(APFixedPoint FX) { assert(isFixedPoint() && "Invalid accessor"); - *(APFixedPoint *)(char *)Data.buffer = std::move(FX); + *(APFixedPoint *)(char *)&Data = std::move(FX); } void setVector(const APValue *E, unsigned N) { MutableArrayRef InternalElts = setVectorUninit(N); @@ -584,15 +584,15 @@ assert(R.getBitWidth() == I.getBitWidth() && "Invalid complex int (type mismatch)."); assert(isComplexInt() && "Invalid accessor"); - ((ComplexAPSInt *)(char *)Data.buffer)->Real = std::move(R); - ((ComplexAPSInt *)(char *)Data.buffer)->Imag = std::move(I); + ((ComplexAPSInt *)(char *)&Data)->Real = std::move(R); + ((ComplexAPSInt *)(char *)&Data)->Imag = std::move(I); } void setComplexFloat(APFloat R, APFloat I) { assert(&R.getSemantics() == &I.getSemantics() && "Invalid complex float (type mismatch)."); assert(isComplexFloat() && "Invalid accessor"); - ((ComplexAPFloat *)(char *)Data.buffer)->Real = std::move(R); - ((ComplexAPFloat *)(char *)Data.buffer)->Imag = std::move(I); + ((ComplexAPFloat *)(char *)&Data)->Real = std::move(R); + ((ComplexAPFloat *)(char *)&Data)->Imag = std::move(I); } void setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr); @@ -602,59 +602,59 @@ void setUnion(const FieldDecl *Field, const APValue &Value); void setAddrLabelDiff(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr) { - ((AddrLabelDiffData*)(char*)Data.buffer)->LHSExpr = LHSExpr; - ((AddrLabelDiffData*)(char*)Data.buffer)->RHSExpr = RHSExpr; + ((AddrLabelDiffData *)(char *)&Data)->LHSExpr = LHSExpr; + ((AddrLabelDiffData *)(char *)&Data)->RHSExpr = RHSExpr; } private: void DestroyDataAndMakeUninit(); void MakeInt() { assert(isAbsent() && "Bad state change"); - new ((void*)Data.buffer) APSInt(1); + new ((void *)&Data) APSInt(1); Kind = Int; } void MakeFloat() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) APFloat(0.0); + new ((void *)(char *)&Data) APFloat(0.0); Kind = Float; } void MakeFixedPoint(APFixedPoint &&FX) { assert(isAbsent() && "Bad state change"); - new ((void *)(char *)Data.buffer) APFixedPoint(std::move(FX)); + new ((void *)(char *)&Data) APFixedPoint(std::move(FX)); Kind = FixedPoint; } void MakeVector() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) Vec(); + new ((void *)(char *)&Data) Vec(); Kind = Vector; } void MakeComplexInt() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) ComplexAPSInt(); + new ((void *)(char *)&Data) ComplexAPSInt(); Kind = ComplexInt; } void MakeComplexFloat() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) ComplexAPFloat(); + new ((void *)(char *)&Data) ComplexAPFloat(); Kind = ComplexFloat; } void MakeLValue(); void MakeArray(unsigned InitElts, unsigned Size); void MakeStruct(unsigned B, unsigned M) { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) StructData(B, M); + new ((void *)(char *)&Data) StructData(B, M); Kind = Struct; } void MakeUnion() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) UnionData(); + new ((void *)(char *)&Data) UnionData(); Kind = Union; } void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember, ArrayRef Path); void MakeAddrLabelDiff() { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) AddrLabelDiffData(); + new ((void *)(char *)&Data) AddrLabelDiffData(); Kind = AddrLabelDiff; } @@ -664,7 +664,7 @@ /// filled in by those steps. MutableArrayRef setVectorUninit(unsigned N) { assert(isVector() && "Invalid accessor"); - Vec *V = ((Vec *)(char *)Data.buffer); + Vec *V = ((Vec *)(char *)&Data); V->Elts = new APValue[N]; V->NumElts = N; return {V->Elts, V->NumElts}; Index: clang/include/clang/AST/ASTTypeTraits.h =================================================================== --- clang/include/clang/AST/ASTTypeTraits.h +++ clang/include/clang/AST/ASTTypeTraits.h @@ -246,9 +246,8 @@ /// in the \c DynTypedNode, and the returned pointer points at /// the storage inside DynTypedNode. For those nodes, do not /// use the pointer outside the scope of the DynTypedNode. - template - const T *get() const { - return BaseConverter::get(NodeKind, Storage.buffer); + template const T *get() const { + return BaseConverter::get(NodeKind, &Storage); } /// Retrieve the stored node as type \c T. @@ -256,7 +255,7 @@ /// Similar to \c get(), but asserts that the type is what we are expecting. template const T &getUnchecked() const { - return BaseConverter::getUnchecked(NodeKind, Storage.buffer); + return BaseConverter::getUnchecked(NodeKind, &Storage); } ASTNodeKind getNodeKind() const { return NodeKind; } @@ -268,7 +267,7 @@ /// method returns NULL. const void *getMemoizationData() const { return NodeKind.hasPointerIdentity() - ? *reinterpret_cast(Storage.buffer) + ? *reinterpret_cast(&Storage) : nullptr; } @@ -403,7 +402,7 @@ static DynTypedNode create(const BaseT &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNode(Node); - new (Result.Storage.buffer) const void *(&Node); + new (&Result.Storage) const void *(&Node); return Result; } }; @@ -423,7 +422,7 @@ static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); - new (Result.Storage.buffer) const void *(&Node); + new (&Result.Storage) const void *(&Node); return Result; } }; @@ -442,7 +441,7 @@ static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); - new (Result.Storage.buffer) T(Node); + new (&Result.Storage) T(Node); return Result; } }; Index: clang/include/clang/AST/ParentMapContext.h =================================================================== --- clang/include/clang/AST/ParentMapContext.h +++ clang/include/clang/AST/ParentMapContext.h @@ -94,25 +94,24 @@ public: DynTypedNodeList(const DynTypedNode &N) : IsSingleNode(true) { - new (Storage.buffer) DynTypedNode(N); + new (&Storage) DynTypedNode(N); } DynTypedNodeList(ArrayRef A) : IsSingleNode(false) { - new (Storage.buffer) ArrayRef(A); + new (&Storage) ArrayRef(A); } const DynTypedNode *begin() const { if (!IsSingleNode) - return reinterpret_cast *>(Storage.buffer) + return reinterpret_cast *>(&Storage) ->begin(); - return reinterpret_cast(Storage.buffer); + return reinterpret_cast(&Storage); } const DynTypedNode *end() const { if (!IsSingleNode) - return reinterpret_cast *>(Storage.buffer) - ->end(); - return reinterpret_cast(Storage.buffer) + 1; + return reinterpret_cast *>(&Storage)->end(); + return reinterpret_cast(&Storage) + 1; } size_t size() const { return end() - begin(); } Index: clang/lib/AST/APValue.cpp =================================================================== --- clang/lib/AST/APValue.cpp +++ clang/lib/AST/APValue.cpp @@ -321,7 +321,7 @@ } case Vector: MakeVector(); - setVector(((const Vec *)(const char *)RHS.Data.buffer)->Elts, + setVector(((const Vec *)(const char *)RHS.& Data)->Elts, RHS.getVectorLength()); break; case ComplexInt: @@ -392,29 +392,29 @@ void APValue::DestroyDataAndMakeUninit() { if (Kind == Int) - ((APSInt*)(char*)Data.buffer)->~APSInt(); + ((APSInt *)(char *)&Data)->~APSInt(); else if (Kind == Float) - ((APFloat*)(char*)Data.buffer)->~APFloat(); + ((APFloat *)(char *)&Data)->~APFloat(); else if (Kind == FixedPoint) - ((APFixedPoint *)(char *)Data.buffer)->~APFixedPoint(); + ((APFixedPoint *)(char *)&Data)->~APFixedPoint(); else if (Kind == Vector) - ((Vec*)(char*)Data.buffer)->~Vec(); + ((Vec *)(char *)&Data)->~Vec(); else if (Kind == ComplexInt) - ((ComplexAPSInt*)(char*)Data.buffer)->~ComplexAPSInt(); + ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt(); else if (Kind == ComplexFloat) - ((ComplexAPFloat*)(char*)Data.buffer)->~ComplexAPFloat(); + ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat(); else if (Kind == LValue) - ((LV*)(char*)Data.buffer)->~LV(); + ((LV *)(char *)&Data)->~LV(); else if (Kind == Array) - ((Arr*)(char*)Data.buffer)->~Arr(); + ((Arr *)(char *)&Data)->~Arr(); else if (Kind == Struct) - ((StructData*)(char*)Data.buffer)->~StructData(); + ((StructData *)(char *)&Data)->~StructData(); else if (Kind == Union) - ((UnionData*)(char*)Data.buffer)->~UnionData(); + ((UnionData *)(char *)&Data)->~UnionData(); else if (Kind == MemberPointer) - ((MemberPointerData*)(char*)Data.buffer)->~MemberPointerData(); + ((MemberPointerData *)(char *)&Data)->~MemberPointerData(); else if (Kind == AddrLabelDiff) - ((AddrLabelDiffData*)(char*)Data.buffer)->~AddrLabelDiffData(); + ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData(); Kind = None; } @@ -448,10 +448,9 @@ "same size."); return getComplexIntReal().needsCleanup(); case LValue: - return reinterpret_cast(Data.buffer)->hasPathPtr(); + return reinterpret_cast(&Data)->hasPathPtr(); case MemberPointer: - return reinterpret_cast(Data.buffer) - ->hasPathPtr(); + return reinterpret_cast(&Data)->hasPathPtr(); } llvm_unreachable("Unknown APValue kind!"); } @@ -885,49 +884,49 @@ const APValue::LValueBase APValue::getLValueBase() const { assert(isLValue() && "Invalid accessor"); - return ((const LV*)(const void*)Data.buffer)->Base; + return ((const LV *)(const void *)&Data)->Base; } bool APValue::isLValueOnePastTheEnd() const { assert(isLValue() && "Invalid accessor"); - return ((const LV*)(const void*)Data.buffer)->IsOnePastTheEnd; + return ((const LV *)(const void *)&Data)->IsOnePastTheEnd; } CharUnits &APValue::getLValueOffset() { assert(isLValue() && "Invalid accessor"); - return ((LV*)(void*)Data.buffer)->Offset; + return ((LV *)(void *)&Data)->Offset; } bool APValue::hasLValuePath() const { assert(isLValue() && "Invalid accessor"); - return ((const LV*)(const char*)Data.buffer)->hasPath(); + return ((const LV *)(const char *)&Data)->hasPath(); } ArrayRef APValue::getLValuePath() const { assert(isLValue() && hasLValuePath() && "Invalid accessor"); - const LV &LVal = *((const LV*)(const char*)Data.buffer); + const LV &LVal = *((const LV *)(const char *)&Data); return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength); } unsigned APValue::getLValueCallIndex() const { assert(isLValue() && "Invalid accessor"); - return ((const LV*)(const char*)Data.buffer)->Base.getCallIndex(); + return ((const LV *)(const char *)&Data)->Base.getCallIndex(); } unsigned APValue::getLValueVersion() const { assert(isLValue() && "Invalid accessor"); - return ((const LV*)(const char*)Data.buffer)->Base.getVersion(); + return ((const LV *)(const char *)&Data)->Base.getVersion(); } bool APValue::isNullPointer() const { assert(isLValue() && "Invalid usage"); - return ((const LV*)(const char*)Data.buffer)->IsNullPtr; + return ((const LV *)(const char *)&Data)->IsNullPtr; } void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr) { assert(isLValue() && "Invalid accessor"); - LV &LVal = *((LV*)(char*)Data.buffer); + LV &LVal = *((LV *)(char *)&Data); LVal.Base = B; LVal.IsOnePastTheEnd = false; LVal.Offset = O; @@ -939,7 +938,7 @@ APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size, bool IsOnePastTheEnd, bool IsNullPtr) { assert(isLValue() && "Invalid accessor"); - LV &LVal = *((LV *)(char *)Data.buffer); + LV &LVal = *((LV *)(char *)&Data); LVal.Base = B; LVal.IsOnePastTheEnd = IsOnePastTheEnd; LVal.Offset = O; @@ -959,42 +958,42 @@ void APValue::setUnion(const FieldDecl *Field, const APValue &Value) { assert(isUnion() && "Invalid accessor"); - ((UnionData *)(char *)Data.buffer)->Field = + ((UnionData *)(char *)&Data)->Field = Field ? Field->getCanonicalDecl() : nullptr; - *((UnionData*)(char*)Data.buffer)->Value = Value; + *((UnionData *)(char *)&Data)->Value = Value; } const ValueDecl *APValue::getMemberPointerDecl() const { assert(isMemberPointer() && "Invalid accessor"); const MemberPointerData &MPD = - *((const MemberPointerData *)(const char *)Data.buffer); + *((const MemberPointerData *)(const char *)&Data); return MPD.MemberAndIsDerivedMember.getPointer(); } bool APValue::isMemberPointerToDerivedMember() const { assert(isMemberPointer() && "Invalid accessor"); const MemberPointerData &MPD = - *((const MemberPointerData *)(const char *)Data.buffer); + *((const MemberPointerData *)(const char *)&Data); return MPD.MemberAndIsDerivedMember.getInt(); } ArrayRef APValue::getMemberPointerPath() const { assert(isMemberPointer() && "Invalid accessor"); const MemberPointerData &MPD = - *((const MemberPointerData *)(const char *)Data.buffer); + *((const MemberPointerData *)(const char *)&Data); return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength); } void APValue::MakeLValue() { assert(isAbsent() && "Bad state change"); static_assert(sizeof(LV) <= DataSize, "LV too big"); - new ((void*)(char*)Data.buffer) LV(); + new ((void *)(char *)&Data) LV(); Kind = LValue; } void APValue::MakeArray(unsigned InitElts, unsigned Size) { assert(isAbsent() && "Bad state change"); - new ((void*)(char*)Data.buffer) Arr(InitElts, Size); + new ((void *)(char *)&Data) Arr(InitElts, Size); Kind = Array; } @@ -1006,7 +1005,7 @@ APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember, unsigned Size) { assert(isAbsent() && "Bad state change"); - MemberPointerData *MPD = new ((void *)(char *)Data.buffer) MemberPointerData; + MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData; Kind = MemberPointer; MPD->MemberAndIsDerivedMember.setPointer( Member ? cast(Member->getCanonicalDecl()) : nullptr); Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -9000,26 +9000,23 @@ Result.MakeVector(); MutableArrayRef Elts = Result.setVectorUninit(FromValue.getVectorLength()); - ImportLoop( - ((const APValue::Vec *)(const char *)FromValue.Data.buffer)->Elts, - Elts.data(), FromValue.getVectorLength()); + ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts, + Elts.data(), FromValue.getVectorLength()); break; } case APValue::Array: Result.MakeArray(FromValue.getArrayInitializedElts(), FromValue.getArraySize()); - ImportLoop( - ((const APValue::Arr *)(const char *)FromValue.Data.buffer)->Elts, - ((const APValue::Arr *)(const char *)Result.Data.buffer)->Elts, - FromValue.getArrayInitializedElts()); + ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts, + ((const APValue::Arr *)(const char *)&Result.Data)->Elts, + FromValue.getArrayInitializedElts()); break; case APValue::Struct: Result.MakeStruct(FromValue.getStructNumBases(), FromValue.getStructNumFields()); ImportLoop( - ((const APValue::StructData *)(const char *)FromValue.Data.buffer) - ->Elts, - ((const APValue::StructData *)(const char *)Result.Data.buffer)->Elts, + ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts, + ((const APValue::StructData *)(const char *)&Result.Data)->Elts, FromValue.getStructNumBases() + FromValue.getStructNumFields()); break; case APValue::Union: { Index: clang/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- clang/lib/Frontend/PrecompiledPreamble.cpp +++ clang/lib/Frontend/PrecompiledPreamble.cpp @@ -735,7 +735,7 @@ PrecompiledPreamble::TempPCHFile &PrecompiledPreamble::PCHStorage::asFile() { assert(getKind() == Kind::TempFile); - return *reinterpret_cast(Storage.buffer); + return *reinterpret_cast(&Storage); } const PrecompiledPreamble::TempPCHFile & @@ -746,7 +746,7 @@ PrecompiledPreamble::InMemoryPreamble & PrecompiledPreamble::PCHStorage::asMemory() { assert(getKind() == Kind::InMemory); - return *reinterpret_cast(Storage.buffer); + return *reinterpret_cast(&Storage); } const PrecompiledPreamble::InMemoryPreamble & Index: llvm/include/llvm/ADT/DenseMap.h =================================================================== --- llvm/include/llvm/ADT/DenseMap.h +++ llvm/include/llvm/ADT/DenseMap.h @@ -1042,7 +1042,7 @@ if (Small) { // First move the inline buckets into a temporary storage. AlignedCharArrayUnion TmpStorage; - BucketT *TmpBegin = reinterpret_cast(TmpStorage.buffer); + BucketT *TmpBegin = reinterpret_cast(&TmpStorage); BucketT *TmpEnd = TmpBegin; // Loop over the buckets, moving non-empty, non-tombstones into the @@ -1132,8 +1132,8 @@ assert(Small); // Note that this cast does not violate aliasing rules as we assert that // the memory's dynamic type is the small, inline bucket buffer, and the - // 'storage.buffer' static type is 'char *'. - return reinterpret_cast(storage.buffer); + // 'storage' is a POD containing a char buffer. + return reinterpret_cast(&storage); } BucketT *getInlineBuckets() { @@ -1144,7 +1144,7 @@ const LargeRep *getLargeRep() const { assert(!Small); // Note, same rule about aliasing as with getInlineBuckets. - return reinterpret_cast(storage.buffer); + return reinterpret_cast(&storage); } LargeRep *getLargeRep() { Index: llvm/include/llvm/ADT/IntervalMap.h =================================================================== --- llvm/include/llvm/ADT/IntervalMap.h +++ llvm/include/llvm/ADT/IntervalMap.h @@ -978,10 +978,7 @@ Allocator &allocator; /// Represent data as a node type without breaking aliasing rules. - template - T &dataAs() const { - return *bit_cast(const_cast(data.buffer)); - } + template T &dataAs() const { return *bit_cast(&data); } const RootLeaf &rootLeaf() const { assert(!branched() && "Cannot acces leaf data in branched root"); @@ -1039,7 +1036,7 @@ public: explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) { - assert((uintptr_t(data.buffer) & (alignof(RootLeaf) - 1)) == 0 && + assert((uintptr_t(&data) & (alignof(RootLeaf) - 1)) == 0 && "Insufficient alignment"); new(&rootLeaf()) RootLeaf(); } Index: llvm/include/llvm/CodeGen/DIE.h =================================================================== --- llvm/include/llvm/CodeGen/DIE.h +++ llvm/include/llvm/CodeGen/DIE.h @@ -383,12 +383,12 @@ static_assert(std::is_standard_layout::value || std::is_pointer::value, "Expected standard layout or pointer"); - new (reinterpret_cast(Val.buffer)) T(V); + new (reinterpret_cast(&Val)) T(V); } - template T *get() { return reinterpret_cast(Val.buffer); } + template T *get() { return reinterpret_cast(&Val); } template const T *get() const { - return reinterpret_cast(Val.buffer); + return reinterpret_cast(&Val); } template void destruct() { get()->~T(); } Index: llvm/include/llvm/Support/AlignOf.h =================================================================== --- llvm/include/llvm/Support/AlignOf.h +++ llvm/include/llvm/Support/AlignOf.h @@ -20,13 +20,11 @@ /// A suitably aligned and sized character array member which can hold elements /// of any type. /// -/// These types may be arrays, structs, or any other types. This exposes a -/// `buffer` member which can be used as suitable storage for a placement new of -/// any of these types. -template struct AlignedCharArrayUnion { - using AlignedUnion = std::aligned_union_t<1, T, Ts...>; - alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)]; -}; +/// These types may be arrays, structs, or any other types. Underneath is a +/// char buffer member which can be used as suitable storage for a placement +/// new of any of these types. +template +using AlignedCharArrayUnion = std::aligned_union_t<1, T, Ts...>; } // end namespace llvm Index: llvm/include/llvm/Support/Error.h =================================================================== --- llvm/include/llvm/Support/Error.h +++ llvm/include/llvm/Support/Error.h @@ -629,22 +629,22 @@ storage_type *getStorage() { assert(!HasError && "Cannot get value when an error exists!"); - return reinterpret_cast(TStorage.buffer); + return reinterpret_cast(&TStorage); } const storage_type *getStorage() const { assert(!HasError && "Cannot get value when an error exists!"); - return reinterpret_cast(TStorage.buffer); + return reinterpret_cast(&TStorage); } error_type *getErrorStorage() { assert(HasError && "Cannot get error when a value exists!"); - return reinterpret_cast(ErrorStorage.buffer); + return reinterpret_cast(&ErrorStorage); } const error_type *getErrorStorage() const { assert(HasError && "Cannot get error when a value exists!"); - return reinterpret_cast(ErrorStorage.buffer); + return reinterpret_cast(&ErrorStorage); } // Used by ExpectedAsOutParameter to reset the checked flag. Index: llvm/include/llvm/Support/ErrorOr.h =================================================================== --- llvm/include/llvm/Support/ErrorOr.h +++ llvm/include/llvm/Support/ErrorOr.h @@ -235,17 +235,17 @@ storage_type *getStorage() { assert(!HasError && "Cannot get value when an error exists!"); - return reinterpret_cast(TStorage.buffer); + return reinterpret_cast(&TStorage); } const storage_type *getStorage() const { assert(!HasError && "Cannot get value when an error exists!"); - return reinterpret_cast(TStorage.buffer); + return reinterpret_cast(&TStorage); } std::error_code *getErrorStorage() { assert(HasError && "Cannot get error when a value exists!"); - return reinterpret_cast(ErrorStorage.buffer); + return reinterpret_cast(&ErrorStorage); } const std::error_code *getErrorStorage() const { Index: llvm/include/llvm/Support/JSON.h =================================================================== --- llvm/include/llvm/Support/JSON.h +++ llvm/include/llvm/Support/JSON.h @@ -456,12 +456,12 @@ friend class Object; template void create(U &&... V) { - new (reinterpret_cast(Union.buffer)) T(std::forward(V)...); + new (reinterpret_cast(&Union)) T(std::forward(V)...); } template T &as() const { // Using this two-step static_cast via void * instead of reinterpret_cast // silences a -Wstrict-aliasing false positive from GCC6 and earlier. - void *Storage = static_cast(Union.buffer); + void *Storage = static_cast(&Union); return *static_cast(Storage); } Index: llvm/lib/Support/JSON.cpp =================================================================== --- llvm/lib/Support/JSON.cpp +++ llvm/lib/Support/JSON.cpp @@ -109,7 +109,7 @@ case T_Boolean: case T_Double: case T_Integer: - memcpy(Union.buffer, M.Union.buffer, sizeof(Union.buffer)); + memcpy(&Union, &M.Union, sizeof(Union)); break; case T_StringRef: create(M.as()); @@ -133,7 +133,7 @@ case T_Boolean: case T_Double: case T_Integer: - memcpy(Union.buffer, M.Union.buffer, sizeof(Union.buffer)); + memcpy(&Union, &M.Union, sizeof(Union)); break; case T_StringRef: create(M.as()); Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -82,11 +82,11 @@ private: bool insaneIntVal(int V) { return V > 4 || V < -4; } - APFloat *getFpValPtr() - { return reinterpret_cast(&FpValBuf.buffer[0]); } + APFloat *getFpValPtr() { return reinterpret_cast(&FpValBuf); } - const APFloat *getFpValPtr() const - { return reinterpret_cast(&FpValBuf.buffer[0]); } + const APFloat *getFpValPtr() const { + return reinterpret_cast(&FpValBuf); + } const APFloat &getFpVal() const { assert(IsFp && BufHasFpVal && "Incorret state");