File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
lib/StaticAnalyzer/Checkers Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -1090,7 +1090,8 @@ static bool isStandardNewDelete(const FunctionDecl *FD) {
10901090 // If the header for operator delete is not included, it's still defined
10911091 // in an invalid source location. Check to make sure we don't crash.
10921092 return !L.isValid () ||
1093- FD->getASTContext ().getSourceManager ().isInSystemHeader (L);
1093+ (!FD->hasBody () && // FIXME: Still a false alarm after CTU inlining.
1094+ FD->getASTContext ().getSourceManager ().isInSystemHeader (L));
10941095}
10951096
10961097// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change 1+ #ifndef OVERLOADED_DELETE_IN_HEADER
2+ #define OVERLOADED_DELETE_IN_HEADER
3+
4+ void clang_analyzer_printState ();
5+
6+ struct DeleteInHeader {
7+ inline void operator delete (void * ptr ) {
8+ // No matter whether this header file is included as a system header file
9+ // with -isystem or a user header file with -I, ptr should not be marked as
10+ // released.
11+ clang_analyzer_printState ();
12+
13+ ::operator delete (ptr ); // The first place where ptr is marked as released.
14+ }
15+ };
16+
17+ #endif // OVERLOADED_DELETE_IN_SYSTEM_HEADER
Original file line number Diff line number Diff line change 1+ // issue 62985
2+ // When 3rd-party header files are included as system headers, their overloaded
3+ // new and delete operators are also considered as the std ones. However, those
4+ // overloaded operator functions will also be inlined. This makes the same
5+ // symbolic memory marked as released twice, which leads to a false uaf alarm.
6+ //
7+ // The first run, include as system header. False uaf report before fix.
8+ //
9+ // RUN: %clang_analyze_cc1 %s \
10+ // RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
11+ // RUN: -isystem %S/Inputs/ 2>&1 | \
12+ // RUN: FileCheck %s
13+ //
14+ // The second run, include as user header. Should always silent.
15+ //
16+ // RUN: %clang_analyze_cc1 %s \
17+ // RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
18+ // RUN: -I %S/Inputs/ 2>&1 | \
19+ // RUN: FileCheck %s
20+
21+ #include " overloaded-delete-in-header.h"
22+
23+ void deleteInHeader (DeleteInHeader *p) { delete p; }
24+
25+ // CHECK-NOT: Released
You can’t perform that action at this time.
0 commit comments