Skip to content

Commit bd1ee48

Browse files
committed
Don't require nullability on 'va_list', even when it's a pointer.
Take 3! This should finally fix the Hexagon, PPC, and Windows bots. rdar://problem/25846421 llvm-svn: 286542
1 parent 9f10af2 commit bd1ee48

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,23 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
38273827
}
38283828
}
38293829

3830+
// Local function that returns true if its argument looks like a va_list.
3831+
auto isVaList = [&S](QualType T) -> bool {
3832+
auto *typedefTy = T->getAs<TypedefType>();
3833+
if (!typedefTy)
3834+
return false;
3835+
TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl();
3836+
do {
3837+
if (typedefTy->getDecl() == vaListTypedef)
3838+
return true;
3839+
if (auto *name = typedefTy->getDecl()->getIdentifier())
3840+
if (name->isStr("va_list"))
3841+
return true;
3842+
typedefTy = typedefTy->desugar()->getAs<TypedefType>();
3843+
} while (typedefTy);
3844+
return false;
3845+
};
3846+
38303847
// Local function that checks the nullability for a given pointer declarator.
38313848
// Returns true if _Nonnull was inferred.
38323849
auto inferPointerNullability = [&](SimplePointerKind pointerKind,
@@ -3905,37 +3922,27 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
39053922
// nullability and perform consistency checking.
39063923
if (S.ActiveTemplateInstantiations.empty()) {
39073924
if (T->canHaveNullability() && !T->getNullability(S.Context)) {
3908-
SimplePointerKind pointerKind = SimplePointerKind::Pointer;
3909-
if (T->isBlockPointerType())
3910-
pointerKind = SimplePointerKind::BlockPointer;
3911-
else if (T->isMemberPointerType())
3912-
pointerKind = SimplePointerKind::MemberPointer;
3913-
3914-
if (auto *attr = inferPointerNullability(
3915-
pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(),
3916-
D.getMutableDeclSpec().getAttributes().getListRef())) {
3917-
T = Context.getAttributedType(
3918-
AttributedType::getNullabilityAttrKind(*inferNullability), T, T);
3919-
attr->setUsedAsTypeAttr();
3925+
if (isVaList(T)) {
3926+
// Record that we've seen a pointer, but do nothing else.
3927+
if (NumPointersRemaining > 0)
3928+
--NumPointersRemaining;
3929+
} else {
3930+
SimplePointerKind pointerKind = SimplePointerKind::Pointer;
3931+
if (T->isBlockPointerType())
3932+
pointerKind = SimplePointerKind::BlockPointer;
3933+
else if (T->isMemberPointerType())
3934+
pointerKind = SimplePointerKind::MemberPointer;
3935+
3936+
if (auto *attr = inferPointerNullability(
3937+
pointerKind, D.getDeclSpec().getTypeSpecTypeLoc(),
3938+
D.getMutableDeclSpec().getAttributes().getListRef())) {
3939+
T = Context.getAttributedType(
3940+
AttributedType::getNullabilityAttrKind(*inferNullability),T,T);
3941+
attr->setUsedAsTypeAttr();
3942+
}
39203943
}
39213944
}
39223945

3923-
auto isVaList = [&S](QualType T) -> bool {
3924-
auto *typedefTy = T->getAs<TypedefType>();
3925-
if (!typedefTy)
3926-
return false;
3927-
TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl();
3928-
do {
3929-
if (typedefTy->getDecl() == vaListTypedef)
3930-
return true;
3931-
if (auto *name = typedefTy->getDecl()->getIdentifier())
3932-
if (name->isStr("va_list"))
3933-
return true;
3934-
typedefTy = typedefTy->desugar()->getAs<TypedefType>();
3935-
} while (typedefTy);
3936-
return false;
3937-
};
3938-
39393946
if (complainAboutMissingNullability == CAMN_Yes &&
39403947
T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
39413948
D.isPrototypeContext() &&

0 commit comments

Comments
 (0)