Skip to content

Commit 9b7fd48

Browse files
nuudlmanenudisa
authored andcommitted
Support non-default address spaces in the cstring checker
1 parent baae949 commit 9b7fd48

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,9 @@ bool CStringChecker::isFirstBufInBound(CheckerContext &C, ProgramStateRef State,
11291129
if (!ER)
11301130
return true; // cf top comment.
11311131

1132-
// FIXME: Does this crash when a non-standard definition
1133-
// of a library function is encountered?
1134-
assert(ER->getValueType() == C.getASTContext().CharTy &&
1132+
// Support library functions defined with non-default address spaces
1133+
assert(ER->getValueType().getCanonicalType().getUnqualifiedType() ==
1134+
C.getASTContext().CharTy &&
11351135
"isFirstBufInBound should only be called with char* ElementRegions");
11361136

11371137
// Get the size of the array.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
2-
// RUN: -analyzer-checker=core -verify %s
2+
// RUN: -analyzer-checker=core,unix -verify %s
33

44
// expected-no-diagnostics
55
//
66
// By default, pointers are 64-bits.
7+
#define ADDRESS_SPACE_64BITS __attribute__((address_space(0)))
78
#define ADDRESS_SPACE_32BITS __attribute__((address_space(3)))
89

910
int test(ADDRESS_SPACE_32BITS int *p, ADDRESS_SPACE_32BITS void *q) {
1011
return p == q; // no-crash
1112
}
13+
14+
// Make sure that the cstring checker handles non-default address spaces
15+
ADDRESS_SPACE_64BITS void *
16+
memcpy(ADDRESS_SPACE_64BITS void *,
17+
ADDRESS_SPACE_32BITS const void *,
18+
long unsigned int);
19+
20+
typedef struct {
21+
char m[1];
22+
} k;
23+
24+
void l(ADDRESS_SPACE_32BITS char *p, ADDRESS_SPACE_64BITS k *n) {
25+
memcpy(&n->m[0], p, 4);
26+
}

0 commit comments

Comments
 (0)