Skip to content

Commit 684c26c

Browse files
authored
[analyzer] Remove redundant "returned to caller" suffix for compound literal in StackAddressEscape
This patch simplifies the diagnostic message in the core.StackAddrEscape for stack memory associated with compound literals by removing the redundant "returned to caller" suffix. Example: https://godbolt.org/z/KxM67vr7c ```c // clang --analyze -Xanalyzer -analyzer-checker=core.StackAddressEscape void* compound_literal() { return &(unsigned short){((unsigned short)0x22EF)}; } ``` warning: Address of stack memory associated with a compound literal declared on line 2 **returned to caller returned to caller** [core.StackAddressEscape]
1 parent 6eb93d0 commit 684c26c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ SourceRange StackAddrEscapeChecker::genName(raw_ostream &os, const MemRegion *R,
7878
const CompoundLiteralExpr *CL = CR->getLiteralExpr();
7979
os << "stack memory associated with a compound literal "
8080
"declared on line "
81-
<< SM.getExpansionLineNumber(CL->getBeginLoc()) << " returned to caller";
81+
<< SM.getExpansionLineNumber(CL->getBeginLoc());
8282
range = CL->getSourceRange();
8383
} else if (const auto *AR = dyn_cast<AllocaRegion>(R)) {
8484
const Expr *ARE = AR->getExpr();

clang/test/Analysis/stack-addr-ps.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ int* f3(int x, int *y) {
2020

2121
void* compound_literal(int x, int y) {
2222
if (x)
23-
return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} expected-warning{{address of stack memory}}
23+
return &(unsigned short){((unsigned short)0x22EF)};
24+
// expected-warning-re@-1{{Address of stack memory associated with a compound literal declared on line {{[0-9]+}} returned to caller [core.StackAddressEscape]}}
25+
// expected-warning@-2{{address of stack memory}}
2426

2527
int* array[] = {};
2628
struct s { int z; double y; int w; };
2729

2830
if (y)
29-
return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of stack memory}} expected-warning{{address of stack memory}}
30-
31+
return &((struct s){ 2, 0.4, 5 * 8 });
32+
// expected-warning-re@-1{{Address of stack memory associated with a compound literal declared on line {{[0-9]+}} returned to caller [core.StackAddressEscape]}}
33+
// expected-warning@-2{{address of stack memory}}
3134

3235
void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });
33-
return p; // expected-warning{{Address of stack memory}}
36+
return p;
37+
// expected-warning-re@-1{{Address of stack memory associated with a compound literal declared on line {{[0-9]+}} returned to caller [core.StackAddressEscape]}}
3438
}
3539

3640
void* alloca_test(void) {

0 commit comments

Comments
 (0)