llvm-project/clang/test
Balazs Benics 6ad47e1c4f [analyzer] Catch leaking stack addresses via stack variables
Not only global variables can hold references to dead stack variables.
Consider this example:

  void write_stack_address_to(char **q) {
    char local;
    *q = &local;
  }

  void test_stack() {
    char *p;
    write_stack_address_to(&p);
  }

The address of 'local' is assigned to 'p', which becomes a dangling
pointer after 'write_stack_address_to()' returns.

The StackAddrEscapeChecker was looking for bindings in the store which
referred to variables of the popped stack frame, but it only considered
global variables in this regard. This patch relaxes this, catching
stack variable bindings as well.

---

This patch also works for temporary objects like:

  struct Bar {
    const int &ref;
    explicit Bar(int y) : ref(y) {
      // Okay.
    } // End of the constructor call, `ref` is dangling now. Warning!
  };

  void test() {
    Bar{33}; // Temporary object, so the corresponding memregion is
             // *not* a VarRegion.
  }

---

The return value optimization aka. copy-elision might kick in but that
is modeled by passing an imaginary CXXThisRegion which refers to the
parent stack frame which is supposed to be the 'return slot'.
Objects residing in the 'return slot' outlive the scope of the inner
call, thus we should expect no warning about them - except if we
explicitly disable copy-elision.

Reviewed By: NoQ, martong

Differential Revision: https://reviews.llvm.org/D107078
2021-08-27 11:31:16 +02:00
..
APINotes
ARCMT
AST [NFC] Drop idle compiler option from the test. 2021-08-13 13:20:11 +03:00
ASTMerge
Analysis [analyzer] Catch leaking stack addresses via stack variables 2021-08-27 11:31:16 +02:00
CXX The maximal representable alignment in LLVM IR is 1GiB, not 512MiB 2021-08-26 12:53:39 +03:00
ClangScanDeps [clang][deps] Reset non-modular language and preprocessor options 2021-08-26 08:43:21 +02:00
CodeCompletion [CodeCompletion] Provide placeholders for known attribute arguments 2021-08-19 14:03:41 +02:00
CodeGen [AST] Pick last tentative definition as the acting definition 2021-08-26 16:49:54 -05:00
CodeGenCUDA [CUDA] Fix static device variables with -fgpu-rdc 2021-08-25 09:31:22 +02:00
CodeGenCXX PR51105: look through ConstantExpr when looking for a braced string literal initialization. 2021-08-25 11:36:11 -07:00
CodeGenCoroutines [Coroutines] Run coroutine passes by default 2021-07-15 14:33:40 +08:00
CodeGenHIP
CodeGenObjC Recommit "[Matrix] Overload stride arg in matrix.columnwise.load/store." 2021-08-12 18:31:57 +01:00
CodeGenObjCXX Reapply [IR] Don't mark mustprogress as type attribute 2021-07-09 20:57:44 +02:00
CodeGenOpenCL [Remarks] [AMDGPU] Emit optimization remarks for atomics generating hardware instructions 2021-08-19 20:51:19 -06:00
CodeGenOpenCLCXX [C++4OpenCL] Introduces __remove_address_space utility 2021-08-06 10:40:22 +01:00
CodeGenSYCL
Coverage Add a target triple to fix failures on MS build bots. 2021-06-30 17:27:26 -07:00
CoverageMapping
Driver [WebAssembly] Add Wasm SjLj option support for clang 2021-08-24 18:12:52 -07:00
FixIt Implement P1949 2021-08-18 07:33:14 -04:00
Format
Frontend [Clang] add support for error+warning fn attrs 2021-08-25 10:34:18 -07:00
Headers Effectively revert 33c3d8a916 / D33782 2021-08-25 14:41:26 -07:00
Import
Index [clang][patch] Remove test artifact before running test for consistent results 2021-07-24 07:55:10 -04:00
Integration
InterfaceStubs [ifs][elfabi] Merge llvm-ifs/elfabi tools 2021-07-19 11:23:19 -07:00
Interpreter Reland "[clang-repl] Allow passing in code as positional arguments." 2021-07-10 17:54:00 +00:00
Layout [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__ 2021-08-05 18:18:58 -04:00
Lexer Implement #pragma clang restrict_expansion 2021-08-23 09:46:38 -07:00
LibClang libclang.so: Make SONAME independent from LLVM version 2021-07-26 16:37:26 -07:00
Misc [Clang] add support for error+warning fn attrs 2021-08-25 10:34:18 -07:00
Modules Clean up test for -f{,no-}implicit-modules-uses-lock 2021-08-16 16:23:04 -07:00
OpenMP [CodeExtractor] Preserve topological order for the return blocks. 2021-08-25 08:09:01 -07:00
PCH Extend diagnostic for out of date AST input file. 2021-08-24 17:03:06 -07:00
Parser Implement P1949 2021-08-18 07:33:14 -04:00
ParserSYCL
Preprocessor [clang][Emscripten] Define __unix family of macros 2021-08-25 19:24:47 -04:00
Profile Update: clang/test/Profile/gcc-flag-compatibility.c to have -flto on AIX 2021-08-09 14:57:38 +00:00
Refactor
Rewriter
Sema [Clang][RISCV] Implement getConstraintRegister for RISC-V 2021-08-26 17:43:43 +01:00
SemaCUDA
SemaCXX The maximal representable alignment in LLVM IR is 1GiB, not 512MiB 2021-08-26 12:53:39 +03:00
SemaObjC [Sema][ObjC] Allow conversions between pointers to ObjC pointers and 2021-08-25 10:22:29 -07:00
SemaObjCXX [clang] C++98 implicit moves are back with a vengeance 2021-07-13 19:16:49 +02:00
SemaOpenCL [OpenCL] Clang diagnostics allow reporting C++ for OpenCL version. 2021-08-13 13:55:22 +01:00
SemaOpenCLCXX [C++][Sema] Ignore top-level qualifiers in casts 2021-07-05 12:22:08 +01:00
SemaSYCL
SemaTemplate
TableGen
Templight
Tooling [clang][tooling] Accept Clang invocations with multiple jobs 2021-07-27 10:47:55 +02:00
Unit
VFS [Modules] Do not remove failed modules after the control block phase 2021-08-17 16:46:51 -07:00
clang-rename
utils/update_cc_test_checks Use installed llvm-lit.py instead of lit.py PR-51072 2021-08-18 09:06:06 +03:00
.clang-format
CMakeLists.txt libclang.so: Make SONAME independent from LLVM version 2021-07-26 16:37:26 -07:00
TestRunner.sh
cxx-sections.data
lit.cfg.py [clang][deps] Substitute clang-scan-deps executable in lit tests 2021-08-04 13:55:14 +02:00
lit.site.cfg.py.in libclang.so: Make SONAME independent from LLVM version 2021-07-26 16:37:26 -07:00
make_test_dirs.pl