Skip to content

Commit 9c56035

Browse files
committed
Revert "[Clang][MS] Remove assertion on BaseOffset can't be smaller than Size."
This reverts commit 5d54213. Breaks check-clang on Windows, see https://reviews.llvm.org/D152472#4422913
1 parent dbdd637 commit 9c56035

File tree

5 files changed

+25
-201
lines changed

5 files changed

+25
-201
lines changed

clang/include/clang/Frontend/LayoutOverrideSource.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ namespace clang {
3030
/// The alignment of the record.
3131
uint64_t Align;
3232

33-
/// The offsets of non-virtual base classes in the record.
34-
SmallVector<CharUnits, 8> BaseOffsets;
35-
36-
/// The offsets of virtual base classes in the record.
37-
SmallVector<CharUnits, 8> VBaseOffsets;
38-
3933
/// The offsets of the fields, in source order.
4034
SmallVector<uint64_t, 8> FieldOffsets;
4135
};

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,8 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
29262926
bool FoundBase = false;
29272927
if (UseExternalLayout) {
29282928
FoundBase = External.getExternalNVBaseOffset(BaseDecl, BaseOffset);
2929-
if (BaseOffset > Size) {
2929+
if (FoundBase) {
2930+
assert(BaseOffset >= Size && "base offset already allocated");
29302931
Size = BaseOffset;
29312932
}
29322933
}
@@ -3722,28 +3723,6 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
37223723
if (Target->defaultsToAIXPowerAlignment())
37233724
OS << " PreferredAlignment:" << toBits(Info.getPreferredAlignment())
37243725
<< "\n";
3725-
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3726-
OS << " BaseOffsets: [";
3727-
const CXXRecordDecl *Base = nullptr;
3728-
for (auto I : CXXRD->bases()) {
3729-
if (I.isVirtual())
3730-
continue;
3731-
if (Base)
3732-
OS << ", ";
3733-
Base = I.getType()->getAsCXXRecordDecl();
3734-
OS << Info.CXXInfo->BaseOffsets[Base].getQuantity();
3735-
}
3736-
OS << "]>\n";
3737-
OS << " VBaseOffsets: [";
3738-
const CXXRecordDecl *VBase = nullptr;
3739-
for (auto I : CXXRD->vbases()) {
3740-
if (VBase)
3741-
OS << ", ";
3742-
VBase = I.getType()->getAsCXXRecordDecl();
3743-
OS << Info.CXXInfo->VBaseOffsets[VBase].VBaseOffset.getQuantity();
3744-
}
3745-
OS << "]>\n";
3746-
}
37473726
OS << " FieldOffsets: [";
37483727
for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
37493728
if (i)

clang/lib/Frontend/LayoutOverrideSource.cpp

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
#include "clang/Frontend/LayoutOverrideSource.h"
99
#include "clang/AST/Decl.h"
10-
#include "clang/AST/DeclCXX.h"
1110
#include "clang/Basic/CharInfo.h"
1211
#include "llvm/Support/raw_ostream.h"
1312
#include <fstream>
@@ -27,18 +26,6 @@ static std::string parseName(StringRef S) {
2726
return S.substr(0, Offset).str();
2827
}
2928

30-
/// Parse an unsigned integer and move S to the next non-digit character.
31-
static bool parseUnsigned(StringRef &S, unsigned long long &ULL) {
32-
if (S.empty() || !isDigit(S[0]))
33-
return false;
34-
unsigned Idx = 1;
35-
while (Idx < S.size() && isDigit(S[Idx]))
36-
++Idx;
37-
(void)S.substr(0, Idx).getAsInteger(10, ULL);
38-
S = S.substr(Idx);
39-
return true;
40-
}
41-
4229
LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
4330
std::ifstream Input(Filename.str().c_str());
4431
if (!Input.is_open())
@@ -93,8 +80,8 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
9380
LineStr = LineStr.substr(Pos + strlen(" Size:"));
9481

9582
unsigned long long Size = 0;
96-
if (parseUnsigned(LineStr, Size))
97-
CurrentLayout.Size = Size;
83+
(void)LineStr.getAsInteger(10, Size);
84+
CurrentLayout.Size = Size;
9885
continue;
9986
}
10087

@@ -105,22 +92,21 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
10592
LineStr = LineStr.substr(Pos + strlen("Alignment:"));
10693

10794
unsigned long long Alignment = 0;
108-
if (parseUnsigned(LineStr, Alignment))
109-
CurrentLayout.Align = Alignment;
95+
(void)LineStr.getAsInteger(10, Alignment);
96+
CurrentLayout.Align = Alignment;
11097
continue;
11198
}
11299

113-
// Check for the size/alignment of the type. The number follows "size=" or
114-
// "align=" indicates number of bytes.
100+
// Check for the size/alignment of the type.
115101
Pos = LineStr.find("sizeof=");
116102
if (Pos != StringRef::npos) {
117103
/* Skip past the sizeof= prefix. */
118104
LineStr = LineStr.substr(Pos + strlen("sizeof="));
119105

120106
// Parse size.
121107
unsigned long long Size = 0;
122-
if (parseUnsigned(LineStr, Size))
123-
CurrentLayout.Size = Size * 8;
108+
(void)LineStr.getAsInteger(10, Size);
109+
CurrentLayout.Size = Size;
124110

125111
Pos = LineStr.find("align=");
126112
if (Pos != StringRef::npos) {
@@ -129,59 +115,34 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
129115

130116
// Parse alignment.
131117
unsigned long long Alignment = 0;
132-
if (parseUnsigned(LineStr, Alignment))
133-
CurrentLayout.Align = Alignment * 8;
118+
(void)LineStr.getAsInteger(10, Alignment);
119+
CurrentLayout.Align = Alignment;
134120
}
135121

136122
continue;
137123
}
138124

139125
// Check for the field offsets of the type.
140126
Pos = LineStr.find("FieldOffsets: [");
141-
if (Pos != StringRef::npos) {
142-
LineStr = LineStr.substr(Pos + strlen("FieldOffsets: ["));
143-
while (!LineStr.empty() && isDigit(LineStr[0])) {
144-
unsigned long long Offset = 0;
145-
if (parseUnsigned(LineStr, Offset))
146-
CurrentLayout.FieldOffsets.push_back(Offset);
147-
148-
// Skip over this offset, the following comma, and any spaces.
149-
LineStr = LineStr.substr(1);
150-
while (!LineStr.empty() && isWhitespace(LineStr[0]))
151-
LineStr = LineStr.substr(1);
152-
}
153-
}
127+
if (Pos == StringRef::npos)
128+
continue;
154129

155-
// Check for the base offsets.
156-
Pos = LineStr.find("BaseOffsets: [");
157-
if (Pos != StringRef::npos) {
158-
LineStr = LineStr.substr(Pos + strlen("BaseOffsets: ["));
159-
while (!LineStr.empty() && isDigit(LineStr[0])) {
160-
unsigned long long Offset = 0;
161-
if (parseUnsigned(LineStr, Offset))
162-
CurrentLayout.BaseOffsets.push_back(CharUnits::fromQuantity(Offset));
130+
LineStr = LineStr.substr(Pos + strlen("FieldOffsets: ["));
131+
while (!LineStr.empty() && isDigit(LineStr[0])) {
132+
// Parse this offset.
133+
unsigned Idx = 1;
134+
while (Idx < LineStr.size() && isDigit(LineStr[Idx]))
135+
++Idx;
163136

164-
// Skip over this offset, the following comma, and any spaces.
165-
LineStr = LineStr.substr(1);
166-
while (!LineStr.empty() && isWhitespace(LineStr[0]))
167-
LineStr = LineStr.substr(1);
168-
}
169-
}
137+
unsigned long long Offset = 0;
138+
(void)LineStr.substr(0, Idx).getAsInteger(10, Offset);
170139

171-
// Check for the virtual base offsets.
172-
Pos = LineStr.find("VBaseOffsets: [");
173-
if (Pos != StringRef::npos) {
174-
LineStr = LineStr.substr(Pos + strlen("VBaseOffsets: ["));
175-
while (!LineStr.empty() && isDigit(LineStr[0])) {
176-
unsigned long long Offset = 0;
177-
if (parseUnsigned(LineStr, Offset))
178-
CurrentLayout.VBaseOffsets.push_back(CharUnits::fromQuantity(Offset));
140+
CurrentLayout.FieldOffsets.push_back(Offset);
179141

180-
// Skip over this offset, the following comma, and any spaces.
142+
// Skip over this offset, the following comma, and any spaces.
143+
LineStr = LineStr.substr(Idx + 1);
144+
while (!LineStr.empty() && isWhitespace(LineStr[0]))
181145
LineStr = LineStr.substr(1);
182-
while (!LineStr.empty() && isWhitespace(LineStr[0]))
183-
LineStr = LineStr.substr(1);
184-
}
185146
}
186147
}
187148

@@ -221,24 +182,6 @@ LayoutOverrideSource::layoutRecordType(const RecordDecl *Record,
221182
if (NumFields != Known->second.FieldOffsets.size())
222183
return false;
223184

224-
// Provide base offsets.
225-
if (const auto *RD = dyn_cast<CXXRecordDecl>(Record)) {
226-
unsigned NumNB = 0;
227-
unsigned NumVB = 0;
228-
for (const auto &I : RD->vbases()) {
229-
if (NumVB >= Known->second.VBaseOffsets.size())
230-
continue;
231-
const CXXRecordDecl *VBase = I.getType()->getAsCXXRecordDecl();
232-
VirtualBaseOffsets[VBase] = Known->second.VBaseOffsets[NumVB++];
233-
}
234-
for (const auto &I : RD->bases()) {
235-
if (I.isVirtual() || NumNB >= Known->second.BaseOffsets.size())
236-
continue;
237-
const CXXRecordDecl *Base = I.getType()->getAsCXXRecordDecl();
238-
BaseOffsets[Base] = Known->second.BaseOffsets[NumNB++];
239-
}
240-
}
241-
242185
Size = Known->second.Size;
243186
Alignment = Known->second.Align;
244187
return true;

clang/test/CodeGenCXX/Inputs/override-layout-ms.layout

Lines changed: 0 additions & 49 deletions
This file was deleted.

clang/test/CodeGenCXX/override-layout-ms.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)