Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,9 @@ bool CStringChecker::isFirstBufInBound(CheckerContext &C, ProgramStateRef State,
if (!ER)
return true; // cf top comment.

// FIXME: Does this crash when a non-standard definition
// of a library function is encountered?
Comment on lines -1132 to -1133
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this FIXME seems to be justified -- I tried declaring memcpy in a wildly nonstandard variant (with int * pointers) and there was no crash.

(No action expected, just mentioning this for other reviewers.)

assert(ER->getValueType() == C.getASTContext().CharTy &&
// Support library functions defined with non-default address spaces
assert(ER->getValueType()->getCanonicalTypeUnqualified() ==
C.getASTContext().CharTy &&
"isFirstBufInBound should only be called with char* ElementRegions");

// Get the size of the array.
Expand Down
18 changes: 17 additions & 1 deletion clang/test/Analysis/element-region-address-space.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
// RUN: -analyzer-checker=core -verify %s
// RUN: -Wno-incompatible-library-redeclaration \
// RUN: -analyzer-checker=core,unix -verify %s

// expected-no-diagnostics
//
// By default, pointers are 64-bits.
#define ADDRESS_SPACE_64BITS __attribute__((address_space(0)))
#define ADDRESS_SPACE_32BITS __attribute__((address_space(3)))

int test(ADDRESS_SPACE_32BITS int *p, ADDRESS_SPACE_32BITS void *q) {
return p == q; // no-crash
}

// Make sure that the cstring checker handles non-default address spaces
ADDRESS_SPACE_64BITS void *
memcpy(ADDRESS_SPACE_64BITS void *,
ADDRESS_SPACE_32BITS const void *,
long unsigned int);

ADDRESS_SPACE_64BITS struct {
char m[16];
} n;

void avoid_cstring_checker_crash(ADDRESS_SPACE_32BITS char *p) {
memcpy(&n.m[0], p, 4); // no-crash
}