[PATCH] D68716: [clang] prevent crash for nonnull attribut in constant context (Bug 43601)
Tyker via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 10 00:21:17 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59c6df9b2c52: [clang] prevent crash for nonnull attribut in constant context (Bug 43601) (authored by Tyker).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68716/new/
https://reviews.llvm.org/D68716
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/attr-nonnull.cpp
Index: clang/test/SemaCXX/attr-nonnull.cpp
===================================================================
--- clang/test/SemaCXX/attr-nonnull.cpp
+++ clang/test/SemaCXX/attr-nonnull.cpp
@@ -77,10 +77,11 @@
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
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5441,18 +5441,18 @@
}
}
}
- 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68716.224269.patch
Type: text/x-patch
Size: 2138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191010/941e638d/attachment.bin>
More information about the cfe-commits
mailing list