Skip to content

Commit e0cfd8a

Browse files
committed
Added basic implementation of auto selection for strucutres of only function pointers
1 parent 753b226 commit e0cfd8a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

clang/include/clang/AST/RecordFieldReorganizer.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RecordFieldReorganizer {
3434
private:
3535
void commit(const RecordDecl *D,
3636
SmallVectorImpl<Decl *> &NewFieldOrder) const;
37+
bool autostructselect(const SmallVector<Decl *,64> fields) const;
3738
};
3839

3940
class Randstruct : public RecordFieldReorganizer {

clang/lib/AST/RecordFieldReorganizer.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ void RecordFieldReorganizer::reorganizeFields(const ASTContext &C,
3535
mutateGuard.insert(f);
3636
fields.push_back(f);
3737
}
38-
38+
if(D->getAttr<RandomizeLayoutAttr>() == nullptr){
39+
if(!autostructselect(fields)){
40+
return;
41+
}
42+
}
3943
// Now allow subclass implementations to reorder the fields
4044
reorganize(C, D, fields);
4145

@@ -50,7 +54,20 @@ void RecordFieldReorganizer::reorganizeFields(const ASTContext &C,
5054

5155
commit(D, fields);
5256
}
53-
57+
bool RecordFieldReorganizer::autostructselect(const SmallVector<Decl *, 64> fields) const {
58+
59+
bool Select = true;
60+
for (auto f : fields){
61+
auto t = f->getFunctionType();
62+
auto s = ((FieldDecl *)f)->getNameAsString();
63+
llvm::errs() << "Function " << s << " type: " << t << "\n";
64+
if(t == nullptr){
65+
Select = false;
66+
break;
67+
}
68+
}
69+
return Select;
70+
}
5471
void RecordFieldReorganizer::commit(
5572
const RecordDecl *D, SmallVectorImpl<Decl *> &NewFieldOrder) const {
5673
Decl *First, *Last;

clang/lib/AST/RecordLayoutBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,7 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
29882988
const ASTRecordLayout *NewEntry = nullptr;
29892989

29902990
bool ShouldBeRandomized = D->getAttr<RandomizeLayoutAttr>() != nullptr;
2991-
if (ShouldBeRandomized) {
2991+
if (true) {
29922992
Randstruct randstruct;
29932993
randstruct.reorganizeFields(*this, D);
29942994
}

0 commit comments

Comments
 (0)