You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[-Wunsafe-buffer-usage] Add basic support for C++ default args
This commit changes two things:
- Allows the count-attributed pointer analysis see through
`CXXDefaultArgExpr` for both pointer and count arguments.
- Fixes the diagnostic location. Since `CXXDefaultArgExpr` has no source
representation, we emit the diagnostic at the right parenthesis of the
call expression.
rdar://156005108
(cherry picked from commit f5a8063)
Copy file name to clipboardExpand all lines: clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp
+41Lines changed: 41 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -664,3 +664,44 @@ static void previous_infinite_loop3(int * __counted_by(n + n * m) p, size_t n,
664
664
previous_infinite_loop3(p, n, q, r, m, o);
665
665
previous_infinite_loop3(p, n, q, r, m, o + 1); // expected-warning 2{{unsafe assignment to function parameter of count-attributed type}}
666
666
}
667
+
668
+
// Check default args.
669
+
670
+
voidcb_def_arg_null_0(int *__counted_by(count) p = nullptr, size_t count = 0);
671
+
672
+
// expected-note@+1{{consider using a safe container and passing '.data()' to the parameter 'p' and '.size()' to its dependent parameter 'count' or 'std::span' and passing '.first(...).data()' to the parameter 'p'}}
673
+
voidcb_def_arg_0_null(size_t count = 0, int *__counted_by(count) p = nullptr);
674
+
675
+
// expected-note@+1 6{{consider using a safe container and passing '.data()' to the parameter 'p' and '.size()' to its dependent parameter 'count' or 'std::span' and passing '.first(...).data()' to the parameter 'p'}}
676
+
voidcb_def_arg_null_42(int *__counted_by(count) p = nullptr, size_t count = 42);
677
+
678
+
voiddefault_arg(std::span<int> sp) {
679
+
cb_def_arg_null_0();
680
+
cb_def_arg_null_0(nullptr);
681
+
cb_def_arg_null_0(nullptr, 0);
682
+
cb_def_arg_null_0(sp.data(), sp.size());
683
+
684
+
cb_def_arg_0_null();
685
+
cb_def_arg_0_null(0);
686
+
cb_def_arg_0_null(0, nullptr);
687
+
cb_def_arg_0_null(sp.size(), sp.data());
688
+
cb_def_arg_0_null(42); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
689
+
cb_def_arg_0_null(42, sp.first(42).data());
690
+
691
+
cb_def_arg_null_42(); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
692
+
cb_def_arg_null_42(nullptr); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
693
+
cb_def_arg_null_42(nullptr, 42); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
694
+
cb_def_arg_null_42(nullptr, 0);
695
+
cb_def_arg_null_42(sp.data()); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
696
+
cb_def_arg_null_42(sp.data(), sp.size());
697
+
cb_def_arg_null_42(sp.first(42).data());
698
+
cb_def_arg_null_42(sp.first(42).data(), 42);
699
+
cb_def_arg_null_42(sp.first(41).data()); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
700
+
701
+
// Check if the diagnostic is at the right paren.
702
+
// clang-format off
703
+
cb_def_arg_null_42
704
+
(
705
+
); // expected-warning{{unsafe assignment to function parameter of count-attributed type}}
0 commit comments