r286522 - Don't require nullability on 'va_list'.
Jordan Rose via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 10 15:28:34 PST 2016
Author: jrose
Date: Thu Nov 10 17:28:34 2016
New Revision: 286522
URL: http://llvm.org/viewvc/llvm-project?rev=286522&view=rev
Log:
Don't require nullability on 'va_list'.
There are many non-portable typedefs, but va_list is one that nobody
ever thinks of as a pointer or an array. (When's the last time you saw
someone check for a NULL va_list?) Make an exception for this one
special type.
Part of rdar://problem/25846421.
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286522&r1=286521&r2=286522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Nov 10 17:28:34 2016
@@ -3919,8 +3919,22 @@ static TypeSourceInfo *GetFullTypeForDec
attr->setUsedAsTypeAttr();
}
}
+
+ auto isVaList = [&S](QualType T) -> bool {
+ auto *typedefTy = T->getAs<TypedefType>();
+ if (!typedefTy)
+ return false;
+ TypedefDecl *vaListTypedef = S.Context.getBuiltinVaListDecl();
+ do {
+ if (typedefTy->getDecl() == vaListTypedef)
+ return true;
+ typedefTy = typedefTy->desugar()->getAs<TypedefType>();
+ } while (typedefTy);
+ return false;
+ };
+
if (complainAboutMissingNullability == CAMN_Yes &&
- T->isArrayType() && !T->getNullability(S.Context) &&
+ T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
D.isPrototypeContext() &&
!hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) {
checkNullabilityConsistency(S, SimplePointerKind::Array,
Modified: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h?rev=286522&r1=286521&r2=286522&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h (original)
+++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-arrays.h Thu Nov 10 17:28:34 2016
@@ -1,3 +1,5 @@
+#include <stdarg.h>
+
void firstThingInTheFileThatNeedsNullabilityIsAnArray(int ints[]);
#if ARRAYS_CHECKED
// expected-warning at -2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
@@ -33,6 +35,26 @@ void testAllOK(
void * _Nullable ptrs[_Nonnull],
void * _Nullable * _Nullable nestedPtrs[_Nonnull]);
+void testVAList(va_list ok); // no warning
+
+#if __cplusplus
+// Carefully construct a test case such that if a platform's va_list is an array
+// or pointer type, it gets tested, but otherwise it does not.
+template<class T, class F>
+struct pointer_like_or { typedef F type; };
+template<class T, class F>
+struct pointer_like_or<T*, F> { typedef T *type; };
+template<class T, class F>
+struct pointer_like_or<T* const, F> { typedef T * const type; };
+template<class T, class F>
+struct pointer_like_or<T[], F> { typedef T type[]; };
+template<class T, class F, unsigned size>
+struct pointer_like_or<T[size], F> { typedef T type[size]; };
+
+void testVAListWithNullability(
+ pointer_like_or<va_list, void*>::type _Nonnull x); // no errors
+#endif
+
void nestedArrays(int x[5][1]) {}
#if ARRAYS_CHECKED
// expected-warning at -2 {{array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)}}
More information about the cfe-commits
mailing list