Skip to content

Commit 334b062

Browse files
author
MalavikaSamak
committed
Fixing the formatting issue and added tests.
1 parent c6d8a58 commit 334b062

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,13 @@ static bool isSafeArraySubscript(const ArraySubscriptExpr &Node,
606606
const Expr *LHS = BE->getLHS();
607607
const Expr *RHS = BE->getRHS();
608608

609-
if(BE->getOpcode() == BO_Rem) {
609+
if (BE->getOpcode() == BO_Rem) {
610610
// If n is a negative number, then n % const can be greater than const
611-
if(!LHS->getType()->isUnsignedIntegerType()) {
611+
if (!LHS->getType()->isUnsignedIntegerType()) {
612612
return false;
613613
}
614614

615-
if(!RHS->isValueDependent() && RHS->EvaluateAsInt(EVResult, Ctx)) {
615+
if (!RHS->isValueDependent() && RHS->EvaluateAsInt(EVResult, Ctx)) {
616616
llvm::APSInt result = EVResult.Val.getInt();
617617
if (result.isNonNegative() && result.getLimitedValue() <= limit)
618618
return true;

clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ void constant_idx_safe0(unsigned idx) {
3535
buffer[0] = 0;
3636
}
3737

38-
int array[10]; // expected-warning 2{{'array' is an unsafe buffer that does not perform bounds checks}}
38+
int array[10]; // expected-warning 3{{'array' is an unsafe buffer that does not perform bounds checks}}
3939

40-
void circular_access_safe(unsigned idx) {
40+
void circular_access_unsigned(unsigned idx) {
4141
array[idx % 10];
42+
array[idx % 11]; // expected-note {{used in buffer access here}}
43+
array[(idx + 3) % 10];
44+
array[(--idx) % 8];
45+
array[idx & 9 % 10];
46+
array[9 & idx % 11];
47+
array [12 % 10];
4248
}
4349

44-
void circular_access_unsafe(int idx) {
50+
void circular_access_signed(int idx) {
4551
array[idx % 10]; // expected-note {{used in buffer access here}}
4652
}
4753

0 commit comments

Comments
 (0)