Skip to content

Commit 22a6eae

Browse files
author
Aaron Eline
committed
Fixing issue #373
1 parent 0481898 commit 22a6eae

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

clang/include/clang/3C/ConstraintVariables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ class PointerVariableConstraint : public ConstraintVariable {
391391
return S->getKind() == PointerVariable;
392392
}
393393

394+
std::string gatherQualStrings(void) const;
395+
394396
std::string mkString(const EnvironmentMap &E, bool EmitName = true,
395397
bool ForItype = false,
396398
bool EmitPointee = false,

clang/lib/3C/ConstraintVariables.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ void PointerVariableConstraint::getQualString(uint32_t TypeIdx,
580580

581581
void PointerVariableConstraint::insertQualType(uint32_t TypeIdx,
582582
QualType &QTy) {
583+
if (QTy.isConstQualified())
583584
if (QTy.isConstQualified())
584585
QualMap[TypeIdx].insert(ConstQualification);
585586
if (QTy.isVolatileQualified())
@@ -653,11 +654,24 @@ void PointerVariableConstraint::setTypedef(TypedefNameDecl* T, std::string s) {
653654
// variables and potentially nested function pointer declaration. Produces a
654655
// string that can be replaced in the source code.
655656

657+
std::string PointerVariableConstraint::gatherQualStrings(void) const {
658+
std::ostringstream S;
659+
uint32_t Idx = 0;
660+
661+
for (auto It = Vars.begin(); It != Vars.end(); It++, Idx++) {
662+
getQualString(Idx, S);
663+
}
664+
665+
return S.str();
666+
}
667+
656668
std::string PointerVariableConstraint::mkString(const EnvironmentMap &E,
657669
bool EmitName, bool ForItype,
658670
bool EmitPointee, bool UnmaskTypedef) const {
659-
if (IsTypedef && !UnmaskTypedef)
660-
return typedefString + (EmitName && getName() != RETVAR ? (" " + getName()) : " ");
671+
if (IsTypedef && !UnmaskTypedef) {
672+
return gatherQualStrings() + typedefString +
673+
(EmitName && getName() != RETVAR ? (" " + getName()) : " ");
674+
}
661675

662676
std::ostringstream Ss;
663677
// This deque will store all the type strings that need to pushed

clang/lib/3C/ProgramInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,10 @@ bool ProgramInfo::seenTypedef(PersistentSourceLoc PSL) {
10421042

10431043
void ProgramInfo::addTypedef(PersistentSourceLoc PSL, bool ShouldCheck,
10441044
TypedefDecl* TD, ASTContext &C) {
1045+
llvm::errs() << "Creating tyepdefvar for " << TD->getNameAsString() << "\n";
1046+
auto Name = "typedef__" + TD->getNameAsString();
10451047
auto* PV = new PointerVariableConstraint(TD->getUnderlyingType(), nullptr,
1046-
TD->getNameAsString(), *this, C);
1048+
Name, *this, C);
10471049
if (ShouldCheck)
10481050
this->typedefVars[PSL] = {*PV};
10491051
else

clang/test/3C/typedefs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ intptr bar(intptr x) {
3232
return x;
3333
}
3434

35+
typedef int* integer;
36+
//CHECK: typedef _Ptr<int> integer;
3537
int foo(void) {
3638
//CHECK: int foo(void) {
3739
int x = 3;
@@ -48,6 +50,10 @@ int foo(void) {
4850
const nat z = 3;
4951
const nat* cnstp = &z;
5052
//CHECK: _Ptr<const nat> cnstp = &z;
53+
int w = 34;
54+
const integer c = &w;
55+
//CHECK: const integer c = &w;
56+
5157

5258
return *p;
5359
}

0 commit comments

Comments
 (0)