[all-commits] [llvm/llvm-project] 1deccd: [analyzer] Retrieve a character from StringLiteral...

Denys Petrov via All-commits all-commits at lists.llvm.org
Fri Oct 29 09:44:52 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1deccd05ba8a326e57a513002f482ed0924b1fd8
      https://github.com/llvm/llvm-project/commit/1deccd05ba8a326e57a513002f482ed0924b1fd8
  Author: Denys Petrov <dpetrov at accesssoftek.com>
  Date:   2021-10-29 (Fri, 29 Oct 2021)

  Changed paths:
    M clang/lib/StaticAnalyzer/Core/RegionStore.cpp
    M clang/test/Analysis/initialization.cpp

  Log Message:
  -----------
  [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

Summary: Assuming that values of constant arrays never change, we can retrieve values for specific position(index) right from the initializer, if presented. Retrieve a character code by index from StringLiteral which is an initializer of constant arrays in global scope.

This patch has a known issue of getting access to characters past the end of the literal. The declaration, in which the literal is used, is an implicit cast of kind `array-to-pointer`. The offset should be in literal length's bounds. This should be distinguished from the states in the Standard C++20 [dcl.init.string] 9.4.2.3. Example:
  const char arr[42] = "123";
  char c = arr[41]; // OK
  const char * const str = "123";
  char c = str[41]; // NOK

Differential Revision: https://reviews.llvm.org/D107339




More information about the All-commits mailing list