diff options
| author | Gauthier Harnisch <tyker1@outlook.com> | 2019-10-10 07:13:20 +0000 |
|---|---|---|
| committer | Gauthier Harnisch <tyker1@outlook.com> | 2019-10-10 07:13:20 +0000 |
| commit | 59c6df9b2c52807d16123e6cef64d5d937b4e697 (patch) | |
| tree | ac16d48811e3caa9b6947c8199270b01e7a630c6 | |
| parent | 12994a70cf798eec60a236d81bb5618a2674fccf (diff) | |
| download | bcm5719-llvm-59c6df9b2c52807d16123e6cef64d5d937b4e697.tar.gz bcm5719-llvm-59c6df9b2c52807d16123e6cef64d5d937b4e697.zip | |
[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
llvm-svn: 374285
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 12 | ||||
| -rw-r--r-- | clang/test/SemaCXX/attr-nonnull.cpp | 7 |
2 files changed, 10 insertions, 9 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 02639679a40..070f784be45 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -5441,18 +5441,18 @@ static bool EvaluateArgs(ArrayRef<const Expr *> Args, ArgVector &ArgValues, } } } - for (ArrayRef<const Expr*>::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/clang/test/SemaCXX/attr-nonnull.cpp b/clang/test/SemaCXX/attr-nonnull.cpp index 764e8d84081..21eedcf376d 100644 --- a/clang/test/SemaCXX/attr-nonnull.cpp +++ b/clang/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 |

