Skip to content

Commit 6dfc782

Browse files
committed
[PP-EXT] Support struct fields in generalization
1 parent 7ff1da9 commit 6dfc782

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6053,18 +6053,24 @@ void CodeGenModule::HandlePPExtensionMethods(
60536053
ArrayRef<llvm::Value*> IdxsTail({Number0, Number1});
60546054
auto* HeadElem = llvm::GetElementPtrInst::CreateInBounds(
60556055
GenRecTy, PtrToObjForGEP, IdxsHead, "pp_head", BB);
6056+
assert(!RecordTy->fields().empty());
6057+
auto firstField = *RecordTy->field_begin();
60566058
auto HeadRecordTy = RecordTy->field_begin()->getType()->getAsRecordDecl();
6057-
if (HeadRecordTy == nullptr) {
6059+
if (!firstField->getName().equals("__pp_head")) {
60586060
// It is a generalization
60596061
HeadRecordTy = RecordTy;
60606062
}
6063+
60616064
int FieldIdx = 0;
6065+
bool SpecTypeWasFound = false;
60626066
for (auto* Field : HeadRecordTy->fields()) {
60636067
if (Field->getName().equals("__pp_specialization_type")) {
6068+
SpecTypeWasFound = true;
60646069
break;
60656070
}
60666071
++FieldIdx;
60676072
}
6073+
assert(SpecTypeWasFound);
60686074
llvm::APInt ApintIdx(32, FieldIdx);
60696075
auto* NumberIdx =
60706076
llvm::ConstantInt::get(

clang/test/CodeGen/Figure.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,11 @@ int not_called_foo() {
305305
void foo_check_cast(void* ptr) {
306306
struct Figure.Circle* fc = (struct Figure.Circle*)ptr;
307307
}
308+
309+
310+
// Check structs inside generalization
311+
struct RectangleCover {
312+
struct Rectangle r;
313+
} <>;
314+
315+
void RectangleLink(struct RectangleCover* rc) {}

0 commit comments

Comments
 (0)