aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaLambda.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-06-26 02:50:04 +0000
committerVedant Kumar <vsk@apple.com>2018-06-26 02:50:04 +0000
commit03dd150a988eb28b29ef24c3202b09e37e1de80f (patch)
tree183a0337016c9b9616b6fa01c7dd4de39d4541a0 /clang/lib/Sema/SemaLambda.cpp
parent2a46384c21a93d827d624e8d00c16377a5c0c12c (diff)
downloadllvm-03dd150a988eb28b29ef24c3202b09e37e1de80f.zip
llvm-03dd150a988eb28b29ef24c3202b09e37e1de80f.tar.gz
llvm-03dd150a988eb28b29ef24c3202b09e37e1de80f.tar.bz2
[ubsan] Relax nullability-return for blocks with deduced types
When the return type of an ObjC-style block literals is deduced, pick the candidate type with the strictest nullability annotation applicable to every other candidate. This suppresses a UBSan false-positive in situations where a too-strict nullability would be deduced, despite the fact that the returned value would be implicitly cast to _Nullable. rdar://41317163 llvm-svn: 335572
Diffstat (limited to 'clang/lib/Sema/SemaLambda.cpp')
-rw-r--r--clang/lib/Sema/SemaLambda.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index b6ea484..98b428b 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -707,8 +707,15 @@ void Sema::deduceClosureReturnType(CapturingScopeInfo &CSI) {
QualType ReturnType =
(RetE ? RetE->getType() : Context.VoidTy).getUnqualifiedType();
if (Context.getCanonicalFunctionResultType(ReturnType) ==
- Context.getCanonicalFunctionResultType(CSI.ReturnType))
+ Context.getCanonicalFunctionResultType(CSI.ReturnType)) {
+ // Use the return type with the strictest possible nullability annotation.
+ auto RetTyNullability = ReturnType->getNullability(Ctx);
+ auto BlockNullability = CSI.ReturnType->getNullability(Ctx);
+ if (BlockNullability &&
+ (!RetTyNullability || *RetTyNullability < *BlockNullability))
+ CSI.ReturnType = ReturnType;
continue;
+ }
// FIXME: This is a poor diagnostic for ReturnStmts without expressions.
// TODO: It's possible that the *first* return is the divergent one.