[all-commits] [llvm/llvm-project] f764dc: [clang] Introduce -fstrict-flex-arrays=<n> for str...

serge-sans-paille via All-commits all-commits at lists.llvm.org
Mon Jul 18 03:46:32 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f764dc99b37e1e6428724a61f36bcb49c015dc70
      https://github.com/llvm/llvm-project/commit/f764dc99b37e1e6428724a61f36bcb49c015dc70
  Author: serge-sans-paille <sguelton at redhat.com>
  Date:   2022-07-18 (Mon, 18 Jul 2022)

  Changed paths:
    M clang/docs/ClangCommandLineReference.rst
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/LangOptions.def
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Sema/SemaChecking.cpp
    M clang/lib/StaticAnalyzer/Core/MemRegion.cpp
    M clang/test/CodeGen/bounds-checking-fam.c
    A clang/test/CodeGen/bounds-checking-fam.cpp
    A clang/test/CodeGen/object-size-flex-array.c
    M clang/test/CodeGenObjC/ubsan-array-bounds.m
    M clang/test/Sema/array-bounds-ptr-arith.c
    A clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
    M clang/test/SemaCXX/array-bounds.cpp

  Log Message:
  -----------
  [clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays

Some code [0] consider that trailing arrays are flexible, whatever their size.
Support for these legacy code has been introduced in
f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of
__builtin_object_size and __builtin_dynamic_object_size in some legit cases.

Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is
desirable.

n = 0: current behavior, any trailing array member is a flexible array. The default.
n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member
n = 2: any trailing array member of undefined or 0 size is a flexible array member

This takes into account two specificities of clang: array bounds as macro id
disqualify FAM, as well as non standard layout.

Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836

[0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions




More information about the All-commits mailing list