From: Gauthier Harnisch Date: Thu, 10 Oct 2019 07:13:20 +0000 (+0000) Subject: [clang] prevent crash for nonnull attribut in constant context (Bug 43601) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5346cfccf3e7ab4c2e268313c05123be3e7380f2;p=clang [clang] prevent crash for nonnull attribut in constant context (Bug 43601) Summary: bug : https://bugs.llvm.org/show_bug.cgi?id=43601 Reviewers: rnk Reviewed By: rnk Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68716 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374285 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 02639679a4..070f784be4 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -5441,18 +5441,18 @@ static bool EvaluateArgs(ArrayRef Args, ArgVector &ArgValues, } } } - for (ArrayRef::iterator I = Args.begin(), E = Args.end(); - I != E; ++I) { - if (!Evaluate(ArgValues[I - Args.begin()], Info, *I)) { + for (unsigned Idx = 0; Idx < Args.size(); Idx++) { + if (!Evaluate(ArgValues[Idx], Info, Args[Idx])) { // If we're checking for a potential constant expression, evaluate all // initializers even if some of them fail. if (!Info.noteFailure()) return false; Success = false; } else if (!ForbiddenNullArgs.empty() && - ForbiddenNullArgs[I - Args.begin()] && - ArgValues[I - Args.begin()].isNullPointer()) { - Info.CCEDiag(*I, diag::note_non_null_attribute_failed); + ForbiddenNullArgs[Idx] && + ArgValues[Idx].isLValue() && + ArgValues[Idx].isNullPointer()) { + Info.CCEDiag(Args[Idx], diag::note_non_null_attribute_failed); if (!Info.noteFailure()) return false; Success = false; diff --git a/test/SemaCXX/attr-nonnull.cpp b/test/SemaCXX/attr-nonnull.cpp index 764e8d8408..21eedcf376 100644 --- a/test/SemaCXX/attr-nonnull.cpp +++ b/test/SemaCXX/attr-nonnull.cpp @@ -77,10 +77,11 @@ constexpr int i3 = f3(&c, 0); //expected-error {{constant expression}} expected- constexpr int i32 = f3(0, &c); __attribute__((nonnull(4))) __attribute__((nonnull)) //expected-error {{out of bounds}} -constexpr int f4(const int*, const int*) { +constexpr int f4(const int*, const int*, int) { return 0; } -constexpr int i4 = f4(&c, 0); //expected-error {{constant expression}} expected-note {{null passed}} -constexpr int i42 = f4(0, &c); //expected-error {{constant expression}} expected-note {{null passed}} +constexpr int i4 = f4(&c, 0, 0); //expected-error {{constant expression}} expected-note {{null passed}} +constexpr int i42 = f4(0, &c, 1); //expected-error {{constant expression}} expected-note {{null passed}} +constexpr int i43 = f4(&c, &c, 0); } \ No newline at end of file