Skip to content

Commit c88e275

Browse files
Make buildItypeDecl use the internal PVConstraint (proof of concept)
1 parent 9fb9cd5 commit c88e275

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

clang/include/clang/3C/DeclRewriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DeclRewriter {
3535
static void rewriteDecls(ASTContext &Context, ProgramInfo &Info, Rewriter &R);
3636

3737
static void
38-
buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl, std::string &Type,
38+
buildItypeDecl(PVConstraint *Int, PVConstraint *Ext, DeclaratorDecl *Decl, std::string &Type,
3939
std::string &IType, ProgramInfo &Info,
4040
ArrayBoundsRewriter &ABR);
4141

@@ -111,7 +111,7 @@ class FunctionDeclBuilder : public RecursiveASTVisitor<FunctionDeclBuilder> {
111111
std::string &Type, std::string &IType,
112112
std::string UseName, bool &RewriteParm,
113113
bool &RewriteRet);
114-
void buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
114+
void buildItypeDecl(PVConstraint *Int, PVConstraint *Ext, DeclaratorDecl *Decl,
115115
std::string &Type, std::string &IType, bool &RewriteParm,
116116
bool &RewriteRet);
117117

clang/lib/3C/DeclRewriter.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ using namespace clang;
3232
// is the taken from the constraint graph solution. The unchecked portion is
3333
// assigned to string reference Type and the checked (itype) portion is assigned
3434
// to the string reference Itype.
35-
void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
35+
void DeclRewriter::buildItypeDecl(PVConstraint *Int, PVConstraint *Ext, DeclaratorDecl *Decl,
3636
std::string &Type, std::string &IType,
3737
ProgramInfo &Info, ArrayBoundsRewriter &ABR) {
38+
PVConstraint *Defn = Ext;
3839
const EnvironmentMap &Env = Info.getConstraints().getVariables();
3940
// True when the type of this variable is defined by a typedef, and the
4041
// constraint variable representing the typedef solved to an unchecked type.
@@ -54,18 +55,20 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
5455
// unchecked portion of the itype. The typedef is used directly in the checked
5556
// portion of the itype.
5657
bool IsCheckedTypedef = Defn->isTypedef() && !IsUncheckedTypedef;
57-
if (IsCheckedTypedef || Defn->getFV()) {
58+
if (IsCheckedTypedef || Defn->getFV() || true /*test*/) {
5859
// Generate the type string from PVC if we need to unmask a typedef, this is
5960
// a function pointer, or this is a constant size array. When unmasking a
6061
// typedef, the expansion of the typedef does not exist in the original
6162
// source, so it must be constructed. For function pointers, a function
6263
// pointer appearing in the unchecked portion of an itype must contain an
6364
// extra set of parenthesis (e.g. `void ((*f)())` instead of `void (f*)()`)
6465
// for the declaration to parse correctly.
65-
Type = Defn->mkString(Info.getConstraints(),
66+
Type = (Int ? Int : Ext)->mkString(Info.getConstraints(),
6667
MKSTRING_OPTS(UnmaskTypedef = IsCheckedTypedef,
67-
ForItypeBase = true));
68-
} else {
68+
ForItypeBase = !Int));
69+
}
70+
#if 0
71+
else {
6972
// In the remaining cases, the unchecked portion of the itype is just the
7073
// original type of the pointer. The first branch tries to generate the type
7174
// using the type and name for this specific declaration. This is important
@@ -84,6 +87,7 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
8487
Type += " ";
8588
}
8689
}
90+
#endif
8791

8892
IType = " : itype(";
8993
IType += Defn->mkString(Info.getConstraints(),
@@ -204,7 +208,7 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
204208
std::string Type, IType;
205209
// VarDecl and FieldDecl subclass DeclaratorDecl, so the cast will
206210
// always succeed.
207-
DeclRewriter::buildItypeDecl(PV, cast<DeclaratorDecl>(D), Type, IType,
211+
DeclRewriter::buildItypeDecl(nullptr, PV, cast<DeclaratorDecl>(D), Type, IType,
208212
Info, ABRewriter);
209213
NewTy += Type + IType;
210214
} else {
@@ -780,12 +784,12 @@ void FunctionDeclBuilder::buildCheckedDecl(
780784
}
781785

782786

783-
void FunctionDeclBuilder::buildItypeDecl(PVConstraint *Defn,
787+
void FunctionDeclBuilder::buildItypeDecl(PVConstraint *Int, PVConstraint *Ext,
784788
DeclaratorDecl *Decl,
785789
std::string &Type, std::string &IType,
786790
bool &RewriteParm, bool &RewriteRet) {
787791
Info.getPerfStats().incrementNumITypes();
788-
DeclRewriter::buildItypeDecl(Defn, Decl, Type, IType, Info, ABRewriter);
792+
DeclRewriter::buildItypeDecl(Int, Ext, Decl, Type, IType, Info, ABRewriter);
789793
RewriteParm = true;
790794
RewriteRet |= isa_and_nonnull<FunctionDecl>(Decl);
791795
}
@@ -804,7 +808,7 @@ void FunctionDeclBuilder::buildDeclVar(const FVComponentVariable *CV,
804808
bool ItypeSolution = CV->hasItypeSolution(Info.getConstraints());
805809
if (ItypeSolution ||
806810
(CheckedSolution && _3COpts.ItypesForExtern && !StaticFunc)) {
807-
buildItypeDecl(CV->getExternal(), Decl, Type, IType, RewriteParm,
811+
buildItypeDecl(CV->getInternal(), CV->getExternal(), Decl, Type, IType, RewriteParm,
808812
RewriteRet);
809813
return;
810814
}

0 commit comments

Comments
 (0)