Skip to content

Commit 3e62c21

Browse files
committed
Fix some issues with array type merging. (No visible difference,
because nothing uses the merged types yet.) llvm-svn: 55161
1 parent 777a6bb commit 3e62c21

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,8 +1849,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) {
18491849
QualType RHSPointee = RHS->getAsPointerType()->getPointeeType();
18501850
QualType ResultType = mergeTypes(LHSPointee, RHSPointee);
18511851
if (ResultType.isNull()) return QualType();
1852-
if (getCanonicalType(LHSPointee) != getCanonicalType(ResultType)) return LHS;
1853-
if (getCanonicalType(RHSPointee) != getCanonicalType(ResultType)) return RHS;
1852+
if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) return LHS;
1853+
if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) return RHS;
18541854
return getPointerType(ResultType);
18551855
}
18561856
case Type::ConstantArray:
@@ -1864,12 +1864,16 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) {
18641864
QualType RHSElem = getAsArrayType(RHS)->getElementType();
18651865
QualType ResultType = mergeTypes(LHSElem, RHSElem);
18661866
if (ResultType.isNull()) return QualType();
1867-
if (LCAT && getCanonicalType(LHSElem) != getCanonicalType(ResultType)) return LHS;
1868-
if (RCAT && getCanonicalType(RHSElem) != getCanonicalType(ResultType)) return RHS;
1867+
if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS;
1868+
if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS;
1869+
if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(),
1870+
ArrayType::ArraySizeModifier(), 0);
1871+
if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(),
1872+
ArrayType::ArraySizeModifier(), 0);
18691873
const VariableArrayType* LVAT = getAsVariableArrayType(LHS);
18701874
const VariableArrayType* RVAT = getAsVariableArrayType(RHS);
1871-
if (LVAT && getCanonicalType(LHSElem) != getCanonicalType(ResultType)) return LHS;
1872-
if (RVAT && getCanonicalType(RHSElem) != getCanonicalType(ResultType)) return RHS;
1875+
if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS;
1876+
if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS;
18731877
if (LVAT) {
18741878
// FIXME: This isn't correct! But tricky to implement because
18751879
// the array's size has to be the size of LHS, but the type
@@ -1882,8 +1886,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) {
18821886
// has to be different.
18831887
return RHS;
18841888
}
1885-
if (getCanonicalType(LHSElem) != getCanonicalType(ResultType)) return LHS;
1886-
if (getCanonicalType(RHSElem) != getCanonicalType(ResultType)) return RHS;
1889+
if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS;
1890+
if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS;
18871891
return getIncompleteArrayType(ResultType, ArrayType::ArraySizeModifier(), 0);
18881892
}
18891893
case Type::FunctionNoProto:

0 commit comments

Comments
 (0)