Don't crash for unparsed or uninstantiated default arguments.
PiperOrigin-RevId: 595435623
Change-Id: Idaac5a8805a8184e7b5f41c22f1f135669c2854b
diff --git a/bazel/llvm.bzl b/bazel/llvm.bzl
index debdf5a..ba41959 100644
--- a/bazel/llvm.bzl
+++ b/bazel/llvm.bzl
@@ -53,7 +53,7 @@
executable = False,
)
-LLVM_COMMIT_SHA = "3c99d25d059fc952a548a342b305a659f1f431d4"
+LLVM_COMMIT_SHA = "923ff5574826767af8145aae361ca5d710c16e65"
def llvm_loader_repository_dependencies():
# This *declares* the dependency, but it won't actually be *downloaded* unless it's used.
diff --git a/nullability/inference/collect_evidence.cc b/nullability/inference/collect_evidence.cc
index 82abd94..9c5e616 100644
--- a/nullability/inference/collect_evidence.cc
+++ b/nullability/inference/collect_evidence.cc
@@ -776,6 +776,42 @@
.takeError();
}
+void collectEvidenceFromDefaultArgument(
+ const clang::FunctionDecl &Fn, const clang::ParmVarDecl &ParamDecl,
+ Slot ParamSlot, llvm::function_ref<EvidenceEmitter> Emit) {
+ // We don't handle all cases of default arguments, because the expressions
+ // used for the argument are not available in any CFG, because the AST nodes
+ // are once-per-decl children of the ParmVarDecl, not once-per-call children
+ // of the CallExpr. Including them in the callsite CFG would be a
+ // significant undertaking, so for now, only handle nullptr literals (and 0)
+ // and expressions whose types already include an annotation, which we can
+ // handle just from declarations instead of call sites and should handle the
+ // majority of cases.
+ if (!isSupportedRawPointerType(ParamDecl.getType().getNonReferenceType()))
+ return;
+ if (!ParamDecl.hasDefaultArg()) return;
+ if (ParamDecl.hasUnparsedDefaultArg() ||
+ ParamDecl.hasUninstantiatedDefaultArg()) {
+ Emit(Fn, ParamSlot, Evidence::UNKNOWN_ARGUMENT, ParamDecl.getEndLoc());
+ return;
+ }
+ const Expr *DefaultArg = ParamDecl.getDefaultArg();
+ CHECK(DefaultArg);
+
+ if (DefaultArg->isNullPointerConstant(Fn.getASTContext(),
+ Expr::NPC_ValueDependentIsNotNull)) {
+ Emit(Fn, ParamSlot, Evidence::NULLABLE_ARGUMENT, DefaultArg->getExprLoc());
+ } else {
+ auto Nullability = getNullabilityAnnotationsFromType(DefaultArg->getType());
+ if (auto K =
+ getArgEvidenceKindFromNullability(Nullability.front().concrete())) {
+ Emit(Fn, ParamSlot, K, DefaultArg->getExprLoc());
+ } else {
+ Emit(Fn, ParamSlot, Evidence::UNKNOWN_ARGUMENT, DefaultArg->getExprLoc());
+ }
+ }
+}
+
void collectEvidenceFromTargetDeclaration(
const clang::Decl &D, llvm::function_ref<EvidenceEmitter> Emit) {
// For now, we can only describe the nullability of functions.
@@ -790,34 +826,7 @@
Emit(*Fn, paramSlot(I), *K, ParamDecl->getTypeSpecStartLoc());
}
- // We don't handle all cases of default arguments, because the expressions
- // used for the argument are not available in any CFG, because the AST nodes
- // are once-per-decl children of the ParmVarDecl, not once-per-call children
- // of the CallExpr. Including them in the callsite CFG would be a
- // significant undertaking, so for now, only handle nullptr literals (and 0)
- // and expressions whose types already include an annotation, which we can
- // handle just from declarations instead of call sites and should handle the
- // majority of cases.
- if (ParamDecl->hasDefaultArg() &&
- isSupportedPointerType(
- ParamDecl->getDefaultArg()->getType().getNonReferenceType())) {
- const Expr *DefaultArg = ParamDecl->getDefaultArg();
- if (DefaultArg->isNullPointerConstant(
- D.getASTContext(), Expr::NPC_ValueDependentIsNotNull)) {
- Emit(*Fn, paramSlot(I), Evidence::NULLABLE_ARGUMENT,
- DefaultArg->getExprLoc());
- } else {
- auto Nullability =
- getNullabilityAnnotationsFromType(DefaultArg->getType());
- if (auto K = getArgEvidenceKindFromNullability(
- Nullability.front().concrete())) {
- Emit(*Fn, paramSlot(I), K, DefaultArg->getExprLoc());
- } else {
- Emit(*Fn, paramSlot(I), Evidence::UNKNOWN_ARGUMENT,
- DefaultArg->getExprLoc());
- }
- }
- }
+ collectEvidenceFromDefaultArgument(*Fn, *ParamDecl, paramSlot(I), Emit);
}
}