r374285 - [clang] prevent crash for nonnull attribut in constant context (Bug 43601)
Gauthier Harnisch via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 10 00:13:20 PDT 2019
Author: tyker
Date: Thu Oct 10 00:13:20 2019
New Revision: 374285
URL: http://llvm.org/viewvc/llvm-project?rev=374285&view=rev
Log:
[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
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/attr-nonnull.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=374285&r1=374284&r2=374285&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Oct 10 00:13:20 2019
@@ -5441,18 +5441,18 @@ static bool EvaluateArgs(ArrayRef<const
}
}
}
- 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;
Modified: cfe/trunk/test/SemaCXX/attr-nonnull.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-nonnull.cpp?rev=374285&r1=374284&r2=374285&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-nonnull.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-nonnull.cpp Thu Oct 10 00:13:20 2019
@@ -77,10 +77,11 @@ constexpr int i3 = f3(&c, 0); //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
More information about the cfe-commits
mailing list